From d6d240a0feec7330db943debc8587c093cb71bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Wed, 4 Mar 2015 09:43:26 +0100 Subject: [PATCH] Refactorred supplier order to match with objectline templates --- htdocs/core/class/commonorder.class.php | 3 +- .../class/fournisseur.commande.class.php | 123 ++++++++-- htdocs/fourn/commande/card.php | 210 ++---------------- htdocs/fourn/facture/card.php | 2 - 4 files changed, 125 insertions(+), 213 deletions(-) diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index 469e1676a53..3e30b0a9ca6 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -22,6 +22,7 @@ */ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; +require_once DOL_DOCUMENT_ROOT .'/core/class/commonobjectline.class.php'; /** * \class CommonOrder @@ -36,7 +37,7 @@ abstract class CommonOrder extends CommonObject * \class CommonOrderLine * \brief Superclass for orders classes */ -abstract class CommonOrderLine extends CommonObject +abstract class CommonOrderLine extends CommonObjectLine { } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 08cf9d4bbf2..e554682e4f5 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -88,6 +88,11 @@ class CommandeFournisseur extends CommonOrder var $extraparams=array(); + /** + * @var CommandeFournisseurLigne[] + */ + public $lines = array(); + /** * Constructor @@ -98,7 +103,6 @@ class CommandeFournisseur extends CommonOrder { $this->db = $db; $this->products = array(); - $this->lines = array(); // List of language codes for status $this->statuts[0] = 'StatusOrderDraft'; @@ -237,6 +241,7 @@ class CommandeFournisseur extends CommonOrder $line = new CommandeFournisseurLigne($this->db); $line->id = $objp->rowid; + $line->rowid = $objp->rowid; $line->desc = $objp->description; // Description ligne $line->description = $objp->description; // Description ligne $line->qty = $objp->qty; @@ -2154,6 +2159,17 @@ class CommandeFournisseur extends CommonOrder if ($nb === 0) return $langs->trans('Undefined'); else return $nb.' '.$langs->trans('Days'); } + + /** + * Returns the rights used for this class + * @return stdClass + */ + public function getRights() + { + global $user; + + return $user->rights->fournisseur->commande; + } } @@ -2163,24 +2179,95 @@ class CommandeFournisseur extends CommonOrder */ class CommandeFournisseurLigne extends CommonOrderLine { - // From llx_commandedet + /** + * Quantity + * @var int + */ var $qty; - var $tva_tx; - var $localtax1_tx; - var $localtax2_tx; - var $localtax1_type; - var $localtax2_type; - var $subprice; - var $remise_percent; - var $desc; // Description ligne - var $fk_product; // Id of predefined product - var $product_type = 0; // Type 0 = product, 1 = Service - var $total_ht; - var $total_tva; - var $total_localtax1; - var $total_localtax2; - var $total_ttc; - var $info_bits; + + /** + * Unit price before taxes + * @var float + */ + public $subprice; + + /** + * Type of the product. 0 for product 1 for service + * @var int + */ + public $product_type = 0; + + /** + * Description of the line + * @var string + */ + var $desc; + + /** + * Id of corresponding product + * @var int + */ + public $fk_product; + + /** + * VAT % + * @var float + */ + public $tva_tx; + + /** + * Local tax 1 % + * @var float + */ + public $localtax1_tx; + + /** + * Local tax 2 % + * @var float + */ + public $localtax2_tx; + + var $localtax1_type; + var $localtax2_type; + + /** + * Total amount before taxes + * @var float + */ + public $total_ht; + + /** + * Total VAT amount + * @var float + */ + public $total_tva; + + /** + * Total local tax 1 amount + * @var float + */ + public $total_localtax1; + + /** + * Total local tax 2 amount + * @var float + */ + public $total_localtax2; + + /** + * Total amount with taxes + * @var float + */ + public $total_ttc; + + /** + * Liste d'options cumulables: + * Bit 0: 0 si TVA normal - 1 si TVA NPR + * Bit 1: 0 si ligne normal - 1 si bit discount (link to line into llx_remise_except) + * @var int + */ + public $info_bits = 0; + var $special_code; var $date_start; var $date_end; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index e6a5aafad38..8c3a75ec991 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -63,6 +63,7 @@ $confirm = GETPOST('confirm','alpha'); $comclientid = GETPOST('comid','int'); $socid = GETPOST('socid','int'); $projectid = GETPOST('projectid','int'); +$lineid = GETPOST('lineid', 'int'); //PDF $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); @@ -404,10 +405,10 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer) */ if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && ! GETPOST('cancel')) { - if ($_POST["elrowid"]) + if ($lineid) { $line = new CommandeFournisseurLigne($db); - $res = $line->fetch($_POST["elrowid"]); + $res = $line->fetch($lineid); if (!$res) dol_print_error($db); } @@ -418,9 +419,9 @@ if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && ! $localtax2_tx=get_localtax($_POST['tva_tx'],2,$mysoc,$object->thirdparty); $result = $object->updateline( - $_POST['elrowid'], - $_POST['eldesc'], - $_POST['pu'], + $lineid, + $_POST['product_desc'], + $_POST['price_ht'], $_POST['qty'], $_POST['remise_percent'], $_POST['tva_tx'], @@ -433,13 +434,14 @@ if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && ! $date_start, $date_end ); + unset($_POST['qty']); unset($_POST['type']); unset($_POST['idprodfournprice']); unset($_POST['remmise_percent']); unset($_POST['dp_desc']); unset($_POST['np_desc']); - unset($_POST['pu']); + unset($_POST['price_ht']); unset($_POST['tva_tx']); unset($_POST['date_start']); unset($_POST['date_end']); @@ -476,7 +478,7 @@ if ($action == 'update_line' && $user->rights->fournisseur->commande->creer && ! if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer) { - $result = $object->deleteline(GETPOST('lineid')); + $result = $object->deleteline($lineid); if ($result >= 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) @@ -1186,7 +1188,7 @@ if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fourniss // Efface un contact else if ($action == 'deletecontact' && $object->id > 0) { - $result = $object->delete_contact($_GET["lineid"]); + $result = $object->delete_contact($lineid); if ($result >= 0) { @@ -1460,10 +1462,9 @@ elseif (! empty($object->id)) /* * Confirmation de la suppression d'une ligne produit */ - if ($action == 'delete_product_line') + if ($action == 'ask_deleteline') { - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2); - + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2); } /* @@ -1695,9 +1696,9 @@ elseif (! empty($object->id)) */ - print '
id.(($action != 'edit_line')?'#add':'#line_'.GETPOST('lineid')).'" method="POST"> + print ' id.(($action != 'edit_line')?'#add':'#line_'.$lineid).'" method="POST"> - + @@ -1707,187 +1708,12 @@ elseif (! empty($object->id)) print ''; - $num = count($object->lines); - $i = 0; $total = 0; - - if ($num) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - $var=true; - while ($i < $num) - { - $line = $object->lines[$i]; - $var=!$var; - - // Show product and description - $type=(! empty($line->product_type)?$line->product_type:(! empty($line->fk_product_type)?$line->fk_product_type:0)); - // Try to enhance type detection using date_start and date_end for free lines where type - // was not saved. - $date_start=''; - $date_end=''; - if (! empty($line->date_start)) - { - $date_start=$line->date_start; - $type=1; - } - if (! empty($line->date_end)) - { - $date_end=$line->date_end; - $type=1; - } - - // Edit line - if ($action != 'edit_line' || $_GET['rowid'] != $line->id) - { - print ''; - - // Show product and description - print ''; - - print ''; - - print '\n"; - - print ''; - - if ($line->remise_percent > 0) - { - print '\n"; - } - else - { - print ''; - } - - print ''; - - if (is_object($hookmanager)) - { - $parameters=array('line'=>$line,'num'=>$num,'i'=>$i); - $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$object,$action); - } - - if ($object->statut == 0 && $user->rights->fournisseur->commande->creer) - { - print ''; - - $actiondelete='delete_product_line'; - print ''; - } - else - { - print ''; - } - print ""; - } - - // Edit line - if ($action == 'edit_line' && $user->rights->fournisseur->commande->creer && ($_GET["rowid"] == $line->id)) - { - print "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print '' . "\n"; - } - $i++; + if ($object->lines) { + $object->printObjectLines($action, $societe, $mysoc, $lineid, 1); } // Form to add new line - if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action != 'edit_line') + if ($object->statut == 0 && $user->rights->fournisseur->commande->creer && $action != 'editline') { // Add free products/services form global $forceall, $senderissupplier, $dateSelector; @@ -2235,7 +2061,7 @@ elseif (! empty($object->id)) // modified by hook if (empty($reshook)) { - if ($user->societe_id == 0 && $action != 'edit_line' && $action != 'delete') + if ($user->societe_id == 0 && $action != 'editline' && $action != 'delete') { print '
'; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 03d742f341d..19685493da5 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1995,8 +1995,6 @@ else //Used in objectline_*.tpl.php to allow supplier invoices enter price with taxes $inputalsopricewithtax = true; - //Used in objectline_*.tpl.php to allow the user to rearrange lines - $allowlinereorder = true; if ($object->lines) { $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
'.$langs->trans('Label').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('TotalHTShort').' 
'; - if ($line->fk_product > 0) - { - print ''; // ancre pour retourner sur la ligne - - $product_static=new ProductFournisseur($db); - $product_static->fetch($line->fk_product); - $text=$product_static->getNomUrl(1,'supplier'); - $text.= ' - '.$product_static->libelle; - $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description)); - print $form->textwithtooltip($text,$description,3,'','',$i); - - // Show range - print_date_range($date_start,$date_end); - - // Add description in form - if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) print ($line->description && $line->description!=$product_static->libelle)?'
'.dol_htmlentitiesbr($line->description):''; - } - - // Description - Editor wysiwyg - if (! $line->fk_product) - { - if ($type==1) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - print $text.' '.nl2br($line->description); - - // Show range - print_date_range($date_start,$date_end); - } - - print '
'.vatrate($line->tva_tx).'%'.price($line->subprice)."'.$line->qty.''.dol_print_reduction($line->remise_percent,$langs)." '.price($line->total_ht).'id.'#'.$line->id.'">'; - print img_edit(); - print ''; - print img_delete(); - print '  
'; - - print ''; - - print ''; // ancre pour retourner sur la ligne - if ((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $line->fk_product > 0) - { - $product_static=new ProductFournisseur($db); - $product_static->fetch($line->fk_product); - $text=$product_static->getNomUrl(1,'supplier'); - $text.= ' - '.$product_static->libelle; - $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description)); - print $form->textwithtooltip($text,$description,3,'','',$i); - - // Show range - print_date_range($date_start,$date_end); - print '
'; - } - else - { - $forceall=1; // For suppliers, we always show all types - print $form->select_type_of_lines($line->product_type,'type',1,0,$forceall); - if ($forceall || (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) - || (empty($conf->product->enabled) && empty($conf->service->enabled))) print '
'; - } - - if (is_object($hookmanager)) - { - $parameters=array('fk_parent_line'=>$line->fk_parent_line, 'line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i); - $reshook=$hookmanager->executeHooks('formEditProductOptions',$parameters,$object,$action); - } - - $nbrows=ROWS_2; - if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT; - $doleditor=new DolEditor('eldesc',$line->description,'',200,'dolibarr_details','',false,true,$conf->global->FCKEDITOR_ENABLE_DETAILS,$nbrows,70); - $doleditor->Create(); - - print '
'; - print $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; - print $form->select_date($date_start,'date_start'.$date_pf,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,''); - print ' '.$langs->trans('to').' '; - print $form->select_date($date_end,'date_end'.$date_pf,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE,1,''); - - print '
'; - print $form->load_tva('tva_tx',$line->tva_tx,$object->thirdparty,$mysoc); - print '%'; - print '