From 7be7a770c1ffe2129e24968bd00e4f83ed1db4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sun, 19 Apr 2015 15:59:49 +0200 Subject: [PATCH] Implemented units for CommandeFournisseur and FactureFournisseur --- htdocs/comm/propal.php | 2 +- htdocs/contrat/card.php | 4 +- .../pdf/pdf_canelle.modules.php | 50 +++++++++++++++-- .../pdf/pdf_muscadet.modules.php | 54 ++++++++++++++++--- htdocs/core/tpl/objectline_edit.tpl.php | 1 - .../class/fournisseur.commande.class.php | 25 +++++---- .../fourn/class/fournisseur.facture.class.php | 18 ++++--- htdocs/fourn/commande/card.php | 22 ++++++-- htdocs/fourn/commande/orderstoinvoice.php | 2 +- htdocs/fourn/facture/card.php | 22 +++++--- .../install/mysql/migration/3.7.0-3.8.0.sql | 8 ++- .../mysql/tables/llx_commande_fournisseur.sql | 2 +- .../llx_commande_fournisseurdet.key.sql | 19 +++++++ .../tables/llx_commande_fournisseurdet.sql | 4 +- .../tables/llx_facture_fourn_det.key.sql | 1 + .../mysql/tables/llx_facture_fourn_det.sql | 3 +- htdocs/product/card.php | 1 + 17 files changed, 192 insertions(+), 46 deletions(-) create mode 100644 htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 10d51feb798..4143f2b8ffd 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -452,7 +452,7 @@ if (empty($reshook)) $tva_tx=get_default_tva($mysoc, $object->thirdparty); - $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options); + $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit); if ($result > 0) { $lineid = $result; diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index d9afbe892ad..2841c709fcc 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -338,7 +338,9 @@ if ($action == 'add' && $user->rights->contrat->creer) 0, $lines[$i]->info_bits, $lines[$i]->fk_fournprice, - $lines[$i]->pa_ht + $lines[$i]->pa_ht, + array(), + $lines[$i]->fk_unit ); if ($result < 0) diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index 8b803eece33..c01dfacd1c3 100644 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -97,6 +97,13 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $this->posxqty=145; $this->posxdiscount=162; $this->postotalht=174; + + if($conf->global->PRODUCT_USE_UNITS) { + $this->posxtva=99; + $this->posxup=114; + $this->posxqty=133; + $this->posxunit=150; + } //if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images if ($this->page_largeur < 210) // To work with US executive format @@ -237,7 +244,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $this->atleastonediscount++; } } - if (empty($this->atleastonediscount)) + if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS)) { $this->posxpicture+=($this->postotalht - $this->posxdiscount); $this->posxtva+=($this->postotalht - $this->posxdiscount); @@ -382,9 +389,30 @@ class pdf_canelle extends ModelePDFSuppliersInvoices $pdf->SetXY($this->posxup, $curY); $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, price($object->lines[$i]->pu_ht), 0, 'R', 0); + // Unit price before discount + $up_excl_tax = pdf_getlineupexcltax($object, $i, $outputlangs, $hidedetails); + $pdf->SetXY($this->posxup, $curY); + $pdf->MultiCell($this->posxqty-$this->posxup-0.8, 3, $up_excl_tax, 0, 'R', 0); + // Quantity $pdf->SetXY($this->posxqty, $curY); - $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $object->lines[$i]->qty, 0, 'R'); + // Enough for 6 chars + if($conf->global->PRODUCT_USE_UNITS) + { + $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R'); + } + else + { + $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R'); + } + + // Unit + if($conf->global->PRODUCT_USE_UNITS) + { + $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager); + $pdf->SetXY($this->posxunit, $curY); + $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L'); + } // Discount on line $pdf->SetXY($this->posxdiscount, $curY); @@ -790,7 +818,23 @@ class pdf_canelle extends ModelePDFSuppliersInvoices if (empty($hidetop)) { $pdf->SetXY($this->posxqty-1, $tab_top+1); - $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); + if($conf->global->PRODUCT_USE_UNITS) + { + $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); + } + else + { + $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); + } + } + + if($conf->global->PRODUCT_USE_UNITS) { + $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height); + if (empty($hidetop)) { + $pdf->SetXY($this->posxunit - 1, $tab_top + 1); + $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', + 'C'); + } } $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height); diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php index ef34c1bf50b..0089790f804 100644 --- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php +++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php @@ -103,11 +103,21 @@ class pdf_muscadet extends ModelePDFSuppliersOrders // Defini position des colonnes $this->posxdesc=$this->marge_gauche+1; - $this->posxtva=112; - $this->posxup=126; - $this->posxqty=145; $this->posxdiscount=162; $this->postotalht=174; + + if ($conf->global->PRODUCT_USE_UNITS) + { + $this->posxtva=99; + $this->posxup=114; + $this->posxqty=133; + $this->posxunit=150; + } else { + $this->posxtva=112; + $this->posxup=126; + $this->posxqty=145; + } + //if (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_WITHOUT_VAT)) $this->posxtva=$this->posxup; $this->posxpicture=$this->posxtva - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images if ($this->page_largeur < 210) // To work with US executive format @@ -245,7 +255,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders $this->atleastonediscount++; } } - if (empty($this->atleastonediscount)) + if (empty($this->atleastonediscount) && empty($conf->global->PRODUCT_USE_UNITS)) { $this->posxpicture+=($this->postotalht - $this->posxdiscount); $this->posxtva+=($this->postotalht - $this->posxdiscount); @@ -392,7 +402,23 @@ class pdf_muscadet extends ModelePDFSuppliersOrders // Quantity $pdf->SetXY($this->posxqty, $curY); - $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 3, $object->lines[$i]->qty, 0, 'R'); + // Enough for 6 chars + if($conf->global->PRODUCT_USE_UNITS) + { + $pdf->MultiCell($this->posxunit-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R'); + } + else + { + $pdf->MultiCell($this->posxdiscount-$this->posxqty-0.8, 4, $object->lines[$i]->qty, 0, 'R'); + } + + // Unit + if($conf->global->PRODUCT_USE_UNITS) + { + $unit = pdf_getlineunit($object, $i, $outputlangs, $hidedetails, $hookmanager); + $pdf->SetXY($this->posxunit, $curY); + $pdf->MultiCell($this->posxdiscount-$this->posxunit-0.8, 4, $unit, 0, 'L'); + } // Discount on line $pdf->SetXY($this->posxdiscount, $curY); @@ -910,7 +936,23 @@ class pdf_muscadet extends ModelePDFSuppliersOrders if (empty($hidetop)) { $pdf->SetXY($this->posxqty-1, $tab_top+1); - $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); + if($conf->global->PRODUCT_USE_UNITS) + { + $pdf->MultiCell($this->posxunit-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); + } + else + { + $pdf->MultiCell($this->posxdiscount-$this->posxqty-1,2, $outputlangs->transnoentities("Qty"),'','C'); + } + } + + if($conf->global->PRODUCT_USE_UNITS) { + $pdf->line($this->posxunit - 1, $tab_top, $this->posxunit - 1, $tab_top + $tab_height); + if (empty($hidetop)) { + $pdf->SetXY($this->posxunit - 1, $tab_top + 1); + $pdf->MultiCell($this->posxdiscount - $this->posxunit - 1, 2, $outputlangs->transnoentities("Unit"), '', + 'C'); + } } $pdf->line($this->posxdiscount-1, $tab_top, $this->posxdiscount-1, $tab_top + $tab_height); diff --git a/htdocs/core/tpl/objectline_edit.tpl.php b/htdocs/core/tpl/objectline_edit.tpl.php index f93595456d2..eb9c7521236 100644 --- a/htdocs/core/tpl/objectline_edit.tpl.php +++ b/htdocs/core/tpl/objectline_edit.tpl.php @@ -129,7 +129,6 @@ $coldisplay=-1; // We remove first td print '>'; } ?> - info_bits & 2) != 2) { // I comment this because it shows info even when not required diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3b6de210928..ddddcf059a3 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -247,6 +247,7 @@ class CommandeFournisseur extends CommonOrder $sql.= " l.localtax1_tx, l. localtax2_tx, l.total_localtax1, l.total_localtax2,"; $sql.= " l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,"; $sql.= " p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc,"; + $sql.= " l.fk_unit,"; $sql.= " l.date_start, l.date_end"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; @@ -297,9 +298,10 @@ class CommandeFournisseur extends CommonOrder $line->date_start = $this->db->jdate($objp->date_start); $line->date_end = $this->db->jdate($objp->date_end); + $line->fk_unit = $objp->fk_unit; - $this->special_line = $objp->special_line; - $this->fk_parent_line = $objp->fk_parent_line; + $this->special_line = $objp->special_line; + $this->fk_parent_line = $objp->fk_parent_line; $this->rang = $objp->rang; @@ -1196,13 +1198,14 @@ class CommandeFournisseur extends CommonOrder * @param int $date_start Date start of service * @param int $date_end Date end of service * @param array $array_options extrafields array + * @param int $fk_unit Id of the unit to use. Null to use the default one * @return int <=0 if KO, >0 if OK */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0) + function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0, $fk_unit = null) { global $langs,$mysoc; - dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2. $fk_product, $fk_prod_fourn_price, $fourn_ref, $remise_percent, $price_base_type, $pu_ttc, $type"); + dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2. $fk_product, $fk_prod_fourn_price, $fourn_ref, $remise_percent, $price_base_type, $pu_ttc, $type, $fk_unit"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Clean parameters @@ -1305,7 +1308,7 @@ class CommandeFournisseur extends CommonOrder $sql.= " (fk_commande, label, description, date_start, date_end,"; $sql.= " fk_product, product_type,"; $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,"; - $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc"; + $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit"; $sql.= ")"; $sql.= " VALUES (".$this->id.", '" . $this->db->escape($label) . "','" . $this->db->escape($desc) . "',"; $sql.= " ".($date_start?"'".$this->db->idate($date_start)."'":"null").","; @@ -1323,7 +1326,8 @@ class CommandeFournisseur extends CommonOrder $sql.= "'".price2num($total_tva)."',"; $sql.= "'".price2num($total_localtax1)."',"; $sql.= "'".price2num($total_localtax2)."',"; - $sql.= "'".price2num($total_ttc)."'"; + $sql.= "'".price2num($total_ttc)."',"; + $sql.= (!$fk_unit ? 'NULL' : $fk_unit); $sql.= ")"; dol_syslog(get_class($this)."::addline", LOG_DEBUG); @@ -1989,12 +1993,13 @@ class CommandeFournisseur extends CommonOrder * @param timestamp $date_start Date start of service * @param timestamp $date_end Date end of service * @param array $array_options extrafields array + * @param int $fk_unit Id of the unit to use. Null to use the default one * @return int < 0 if error, > 0 if ok */ - function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0) + function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null) { global $mysoc; - dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type"); + dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; if ($this->brouillon) @@ -2061,6 +2066,7 @@ class CommandeFournisseur extends CommonOrder $sql.= ",total_localtax2='".price2num($total_localtax2)."'"; $sql.= ",total_ttc='".price2num($total_ttc)."'"; $sql.= ",product_type=".$type; + $sql.= ",fk_unit=".(!$fk_unit ? 'NULL' : $fk_unit); $sql.= " WHERE rowid = ".$rowid; dol_syslog(get_class($this)."::updateline", LOG_DEBUG); @@ -2493,7 +2499,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql.= ' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,'; $sql.= ' cd.total_localtax1, cd.total_localtax2,'; $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc,'; - $sql.= ' cd.date_start, cd.date_end'; + $sql.= ' cd.date_start, cd.date_end, cd.fk_unit'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid'; $sql.= ' WHERE cd.rowid = '.$rowid; @@ -2526,6 +2532,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $this->date_start = $this->db->jdate($objp->date_start); $this->date_end = $this->db->jdate($objp->date_end); + $this->fk_unit = $objp->fk_unit; $this->db->free($result); return 1; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 59ea5544681..dd4e5f598d2 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -480,7 +480,7 @@ class FactureFournisseur extends CommonInvoice { $sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx'; $sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 '; - $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line'; + $sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit'; $sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid'; @@ -531,6 +531,7 @@ class FactureFournisseur extends CommonInvoice $this->lines[$i]->fk_parent_line = $obj->fk_parent_line; $this->lines[$i]->special_code = $obj->special_code; $this->lines[$i]->rang = $obj->rang; + $this->lines[$i]->fk_unit = $obj->fk_unit; $i++; } @@ -1117,13 +1118,14 @@ class FactureFournisseur extends CommonInvoice * @param int $rang Position of line * @param int $notrigger Disable triggers * @param array $array_options extrafields array + * @param int $fk_unit Id of the unit to use. Null to use the default one * @return int >0 if OK, <0 if KO * * FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order. */ - function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0) + function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit = null) { - dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type", LOG_DEBUG); + dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Clean parameters @@ -1158,7 +1160,7 @@ class FactureFournisseur extends CommonInvoice { $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); - $result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true, '', '', $array_options); + $result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true, '', '', $array_options, $fk_unit); if ($result > 0) { $this->rowid = $idligne; @@ -1213,12 +1215,13 @@ class FactureFournisseur extends CommonInvoice * @param timestamp $date_start Date start of service * @param timestamp $date_end Date end of service * @param array $array_options extrafields array + * @param int $fk_unit Id of the unit to use. Null to use the default one * @return int <0 if KO, >0 if OK */ - function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0) + function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null) { global $mysoc; - dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent", LOG_DEBUG); + dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent,$fk_unit", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; $pu = price2num($pu); @@ -1288,6 +1291,7 @@ class FactureFournisseur extends CommonInvoice else $sql.= ", fk_product = null"; $sql.= ", product_type = ".$product_type; $sql.= ", info_bits = ".$info_bits; + $sql .= ", fk_unit=".(!$fk_unit ? 'NULL' : $fk_unit); $sql.= " WHERE rowid = ".$id; dol_syslog(get_class($this)."::updateline", LOG_DEBUG); @@ -1877,7 +1881,7 @@ class FactureFournisseur extends CommonInvoice /** * Class to manage line invoices */ -class SupplierInvoiceLine extends CommonInvoice +class SupplierInvoiceLine extends CommonObjectLine { public $element='facture_fourn_det'; public $table_element='facture_fourn_det'; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index fe6751c28f2..113758b7ee9 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -347,7 +347,8 @@ if (empty($reshook)) '', $date_start, $date_end, - $array_options + $array_options, + $productsupplier->fk_unit ); } if ($idprod == -99 || $idprod == 0) @@ -375,6 +376,12 @@ if (empty($reshook)) $desc = $product_desc; $type = GETPOST('type'); + $fk_unit= GETPOST('units', 'int'); + + if ($fk_unit <= 0) { + $fk_unit = null; + } + $tva_tx = price2num($tva_tx); // When vat is text input field // Local Taxes @@ -385,15 +392,16 @@ if (empty($reshook)) { $price_base_type = 'HT'; $ht = price2num(GETPOST('price_ht')); - $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, 0, $type,'','', $date_start, $date_end, $array_options); + $ttc = 0; } else { $ttc = price2num(GETPOST('price_ttc')); $ht = $ttc / (1 + ($tva_tx / 100)); $price_base_type = 'HT'; - $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options); } + + $result=$object->addline($desc, $ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $remise_percent, $price_base_type, $ttc, $type,'','', $date_start, $date_end, $array_options, $fk_unit); } //print "xx".$tva_tx; exit; @@ -513,7 +521,8 @@ if (empty($reshook)) false, $date_start, $date_end, - $array_options + $array_options, + $_POST['units'] ); unset($_POST['qty']); unset($_POST['type']); @@ -525,6 +534,7 @@ if (empty($reshook)) unset($_POST['tva_tx']); unset($_POST['date_start']); unset($_POST['date_end']); + unset($_POST['units']); unset($localtax1_tx); unset($localtax2_tx); @@ -989,7 +999,9 @@ if (empty($reshook)) '', '', null, - null + null, + array(), + $lines[$i]->fk_unit ); if ($result < 0) { diff --git a/htdocs/fourn/commande/orderstoinvoice.php b/htdocs/fourn/commande/orderstoinvoice.php index 6cd0dfb02c2..d35d318d4a2 100644 --- a/htdocs/fourn/commande/orderstoinvoice.php +++ b/htdocs/fourn/commande/orderstoinvoice.php @@ -207,7 +207,7 @@ if (($action == 'create' || $action == 'add') && empty($mesgs)) { $fk_parent_line = 0; } // FIXME Missing $lines[$i]->ref_supplier and $lines[$i]->label into addline and updateline methods. They are filled when coming from order for example. - $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->qty, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, 'HT', $product_type); + $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->qty, $lines[$i]->fk_product, $lines[$i]->remise_percent, $date_start, $date_end, 0, $lines[$i]->info_bits, 'HT', $product_type, -1, false, 0, $lines[$i]->fk_unit); if ($result > 0) { $lineid = $result; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 4c401c2c540..edac67e3fbf 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -444,7 +444,8 @@ if (empty($reshook)) $product_type, $lines[$i]->rang, 1, - $lines[$i]->array_options + $lines[$i]->array_options, + $lines[$i]->fk_unit ); if ($result < 0) @@ -587,7 +588,7 @@ if (empty($reshook)) } } - $result=$object->updateline(GETPOST('lineid'), $label, $up, $tva_tx, $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('productid'), $price_base_type, 0, $type, $remise_percent, 0, $date_start, $date_end, $array_options); + $result=$object->updateline(GETPOST('lineid'), $label, $up, $tva_tx, $localtax1_tx, $localtax2_tx, GETPOST('qty'), GETPOST('productid'), $price_base_type, 0, $type, $remise_percent, 0, $date_start, $date_end, $array_options, $_POST['units']); if ($result >= 0) { unset($_POST['label']); @@ -684,6 +685,7 @@ if (empty($reshook)) $idprod=$productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty); // Just to see if a price exists for the quantity. Not used to found vat. } + //Replaces $fk_unit with the product's if ($idprod > 0) { $result=$productsupplier->fetch($idprod); @@ -703,7 +705,7 @@ if (empty($reshook)) $price_base_type = 'HT'; // TODO Save the product supplier ref into database into field ref_supplier (must rename field ref into ref_supplier first) - $result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, '', '', 0, $npr, $price_base_type, $type, -1, 0, $array_options); + $result=$object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, '', '', 0, $npr, $price_base_type, $type, -1, 0, $array_options, $productsupplier->fk_unit); } if ($idprod == -2 || $idprod == 0) { @@ -730,6 +732,12 @@ if (empty($reshook)) $desc = $product_desc; $type = GETPOST('type'); + $fk_unit= GETPOST('units', 'int'); + + if ($fk_unit <= 0) { + $fk_unit = null; + } + $tva_tx = price2num($tva_tx); // When vat is text input field // Local Taxes @@ -740,18 +748,15 @@ if (empty($reshook)) { $ht = price2num($_POST['price_ht']); $price_base_type = 'HT'; - - //print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0 - $result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options); } else { $ttc = price2num($_POST['price_ttc']); $ht = $ttc / (1 + ($tva_tx / 100)); $price_base_type = 'HT'; - //print $product_desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0 - $result=$object->addline($product_desc, $ht, $tva_tx,$localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options); } + + $result=$object->addline($product_desc, $ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $datestart, $dateend, 0, $npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit); } //print "xx".$tva_tx; exit; @@ -793,6 +798,7 @@ if (empty($reshook)) unset($_POST['np_markRate']); unset($_POST['dp_desc']); unset($_POST['idprodfournprice']); + unset($_POST['units']); unset($_POST['date_starthour']); unset($_POST['date_startmin']); diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 586ee98150d..68f918d7605 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -576,4 +576,10 @@ alter table llx_commandedet add fk_unit integer default NULL; ALTER TABLE llx_commandedet ADD CONSTRAINT fk_commandedet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); alter table llx_contratdet add fk_unit integer default NULL; -ALTER TABLE llx_contratdet ADD CONSTRAINT fk_contratdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); \ No newline at end of file +ALTER TABLE llx_contratdet ADD CONSTRAINT fk_contratdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); + +alter table llx_commande_fournisseurdet add fk_unit integer default NULL; +ALTER TABLE llx_commande_fournisseurdet ADD CONSTRAINT fk_commande_fournisseurdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); + +alter table llx_facture_fourn_det add fk_unit integer default NULL; +ALTER TABLE llx_facture_fourn_det ADD CONSTRAINT fk_facture_fourn_det_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseur.sql b/htdocs/install/mysql/tables/llx_commande_fournisseur.sql index 33588d8bf66..3b1dee31b9e 100644 --- a/htdocs/install/mysql/tables/llx_commande_fournisseur.sql +++ b/htdocs/install/mysql/tables/llx_commande_fournisseur.sql @@ -66,5 +66,5 @@ create table llx_commande_fournisseur location_incoterms varchar(255), -- for incoterms import_key varchar(14), extraparams varchar(255) -- for stock other parameters with json format - + )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql new file mode 100644 index 00000000000..99d953ec17c --- /dev/null +++ b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.key.sql @@ -0,0 +1,19 @@ +-- ============================================================================ +-- Copyright (C) 2015 Marcos García +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . +-- +-- ============================================================================ + +ALTER TABLE llx_commande_fournisseurdet ADD CONSTRAINT fk_commande_fournisseurdet_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql index cb2ec488272..a3dbd87d359 100644 --- a/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql +++ b/htdocs/install/mysql/tables/llx_commande_fournisseurdet.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2007 Rodolphe Quiedeville -- Copyright (C) 2007-2009 Laurent Destailleur -- Copyright (C) 2010-2012 Juanjo Menent +-- Copyright (C) 2015 Marcos García -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -47,5 +48,6 @@ create table llx_commande_fournisseurdet info_bits integer DEFAULT 0, -- TVA NPR ou non special_code integer DEFAULT 0, -- code pour les lignes speciales rang integer DEFAULT 0, - import_key varchar(14) + import_key varchar(14), + fk_unit integer DEFAULT NULL )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql b/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql index 907f09360a1..2048cf06024 100644 --- a/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql +++ b/htdocs/install/mysql/tables/llx_facture_fourn_det.key.sql @@ -22,3 +22,4 @@ ALTER TABLE llx_facture_fourn_det ADD INDEX idx_facture_fourn_det_fk_facture (fk_facture_fourn); ALTER TABLE llx_facture_fourn_det ADD CONSTRAINT fk_facture_fourn_det_fk_facture FOREIGN KEY (fk_facture_fourn) REFERENCES llx_facture_fourn (rowid); +ALTER TABLE llx_facture_fourn_det ADD CONSTRAINT fk_facture_fourn_det_fk_unit FOREIGN KEY (fk_unit) REFERENCES llx_c_units (rowid); \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_facture_fourn_det.sql b/htdocs/install/mysql/tables/llx_facture_fourn_det.sql index 3985d0d3483..ad066752ea0 100644 --- a/htdocs/install/mysql/tables/llx_facture_fourn_det.sql +++ b/htdocs/install/mysql/tables/llx_facture_fourn_det.sql @@ -48,5 +48,6 @@ create table llx_facture_fourn_det fk_code_ventilation integer DEFAULT 0 NOT NULL, special_code integer DEFAULT 0, -- code pour les lignes speciales rang integer DEFAULT 0, - import_key varchar(14) + import_key varchar(14), + fk_unit integer DEFAULT NULL )ENGINE=innodb; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 475be8fdf79..eaef488dac3 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -244,6 +244,7 @@ if (empty($reshook)) $object->volume_units = GETPOST('volume_units'); $object->finished = GETPOST('finished'); $object->hidden = GETPOST('hidden')=='yes'?1:0; + $object->fk_unit = GETPOST('units'); if ($fk_unit > 0) { $object->fk_unit = $fk_unit; }