diff --git a/htdocs/comm/address.php b/htdocs/comm/address.php index eb3c51b1760..edb5042e358 100644 --- a/htdocs/comm/address.php +++ b/htdocs/comm/address.php @@ -106,7 +106,7 @@ if ($action == 'add' || $action == 'update') } else { - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $action='create'; } } @@ -147,7 +147,7 @@ if ($action == 'add' || $action == 'update') else { $reload = 0; - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $action= "edit"; } } diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index b874eeefde5..3083ac9505c 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -105,7 +105,7 @@ if (empty($reshook)) $result=$object->fetch($id); $object->code_compta=$_POST["customeraccountancycode"]; $result=$object->update($object->id,$user,1,1,0); - if ($result < 0) setEventMessage($object->error,$object->errors,'errors'); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // conditions de reglement @@ -113,7 +113,7 @@ if (empty($reshook)) { $object->fetch($id); $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int')); - if ($result < 0) setEventMessage($object->error,$object->errors,'errors'); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // mode de reglement @@ -121,7 +121,7 @@ if (empty($reshook)) { $object->fetch($id); $result=$object->setPaymentMethods(GETPOST('mode_reglement_id','int')); - if ($result < 0) setEventMessage($object->error,$object->errors,'errors'); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // assujetissement a la TVA @@ -130,7 +130,7 @@ if (empty($reshook)) $object->fetch($id); $object->tva_assuj=$_POST['assujtva_value']; $result=$object->update($object->id); - if ($result < 0) setEventMessage($object->error,$object->errors,'errors'); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // set prospect level @@ -157,7 +157,7 @@ if (empty($reshook)) $object->fetch($id); $object->outstanding_limit=GETPOST('outstanding_limit'); $result=$object->set_OutstandingBill($user); - if ($result < 0) setEventMessage($object->error,$object->errors,'errors'); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } } diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 2a892033865..e54aeb1c8a5 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -359,7 +359,7 @@ if (empty($reshook)) { $statut=2; // Status 'sent partially' (because at least one error) if ($nbok > 0) setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs'); - else setEventMessage($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs'); + else setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs'); } else { diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 408d01d8eaa..1107e3b9b4d 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -6,7 +6,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2014 Juanjo Menent - * Copyright (C) 2010-2011 Philippe Grand + * Copyright (C) 2010-2015 Philippe Grand * Copyright (C) 2012-2013 Christophe Battarel * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013-2014 Florian Henry @@ -131,7 +131,7 @@ if (empty($reshook)) { if (! GETPOST('socid', 3)) { - setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors'); + setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { @@ -141,7 +141,7 @@ if (empty($reshook)) header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result); exit(); } else { - if (count($object->errors) > 0) setEventMessage($object->errors, 'errors'); + if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors'); $action = ''; } } @@ -157,7 +157,7 @@ if (empty($reshook)) exit(); } else { $langs->load("errors"); - setEventMessage($langs->trans($object->error), 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } @@ -211,8 +211,8 @@ if (empty($reshook)) } } else { $langs->load("errors"); - if (count($object->errors) > 0) setEventMessage($object->errors, 'errors'); - else setEventMessage($langs->trans($object->error), 'errors'); + if (count($object->errors) > 0) setEventMessages($object->error, $object->errors, 'errors'); + else setEventMessages($langs->trans($object->error), null, 'errors'); } } @@ -318,7 +318,7 @@ if (empty($reshook)) $id = $object->create_from($user); } else { - setEventMessage($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), 'errors'); + setEventMessages($langs->trans("ErrorFailedToCopyProposal", GETPOST('copie_propal')), null, 'errors'); } } else { $object->ref = GETPOST('ref'); @@ -507,7 +507,7 @@ if (empty($reshook)) if ($result < 0) { $error++; - setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors'); + setEventMessages($langs->trans("ErrorFailedToAddContact"), null, 'errors'); } } @@ -671,7 +671,7 @@ if (empty($reshook)) if ($object->id > 0) { $result = $object->insert_discount($_POST["remise_id"]); if ($result < 0) { - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } @@ -875,7 +875,7 @@ if (empty($reshook)) if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); - setEventMessage($mesg, 'errors'); + setEventMessages($mesg, null, 'errors'); } else { // Insert line $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $pu_ttc, $info_bits, $type, - 1, 0, GETPOST('fk_parent_line'), $fournprice, $buyingprice, $label, $date_start, $date_end, $array_options, $fk_unit); @@ -929,13 +929,13 @@ if (empty($reshook)) } else { $db->rollback(); - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } } - // Mise a jour d'une ligne dans la propale + // Update a line within proposal else if ($action == 'updateligne' && $user->rights->propal->creer && GETPOST('save')) { // Define info_bits @@ -991,7 +991,7 @@ if (empty($reshook)) $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); if ($price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) { - setEventMessage($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), 'errors'); + setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); $error ++; } } else { @@ -1040,7 +1040,7 @@ if (empty($reshook)) } else { $db->rollback(); - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } @@ -1137,9 +1137,9 @@ if (empty($reshook)) } else { if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); - setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors'); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); } else { - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } @@ -1636,13 +1636,13 @@ if ($action == 'create') else if ($action == 'validate') { $error = 0; - // on verifie si l'objet est en numerotation provisoire + // We verifie whether the object is provisionally numbering $ref = substr($object->ref, 1, 4); if ($ref == 'PROV') { $numref = $object->getNextNumRef($soc); if (empty($numref)) { $error ++; - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } else { $numref = $object->ref; diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 6a0a1076e62..544c5ab27e3 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Patrick Rouillon * Copyright (C) 2005-2009 Destailleur Laurent * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2011-2012 Philippe Grand + * Copyright (C) 2011-2015 Philippe Grand * * 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 @@ -54,12 +54,12 @@ if ($id > 0 || ! empty($ref)) if ($ret == 0) { $langs->load("errors"); - setEventMessage($langs->trans('ErrorRecordNotFound'), 'errors'); + setEventMessages($langs->trans('ErrorRecordNotFound'), null, 'errors'); $error++; } else if ($ret < 0) { - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); $error++; } } @@ -75,7 +75,7 @@ else /* - * Ajout d'un nouveau contact + * Add a new contact */ if ($action == 'addcontact' && $user->rights->propale->creer) @@ -96,16 +96,16 @@ if ($action == 'addcontact' && $user->rights->propale->creer) if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); - setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors'); + setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); } else { - setEventMessage($object->error, 'errors'); + setEventMessages($object->error, $object->errors, 'errors'); } } } -// Bascule du statut d'un contact +// Toggle the status of a contact else if ($action == 'swapstatut' && $user->rights->propale->creer) { if ($object->id > 0) @@ -114,7 +114,7 @@ else if ($action == 'swapstatut' && $user->rights->propale->creer) } } -// Efface un contact +// Deletes a contact else if ($action == 'deletecontact' && $user->rights->propale->creer) { $result = $object->delete_contact($lineid); diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index e472c5fb848..ba85d593fce 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -65,17 +65,17 @@ if ($action == 'confirm_split' && GETPOST("confirm") == 'yes') if (! $res > 0) { $error++; - setEventMessage($langs->trans("ErrorFailedToLoadDiscount"), 'errors'); + setEventMessages($langs->trans("ErrorFailedToLoadDiscount"), null, 'errors'); } if (! $error && price2num($_POST["amount_ttc_1"]+$_POST["amount_ttc_2"]) != $discount->amount_ttc) { $error++; - setEventMessage($langs->trans("TotalOfTwoDiscountMustEqualsOriginal"), 'errors'); + setEventMessages($langs->trans("TotalOfTwoDiscountMustEqualsOriginal"), null, 'errors'); } if (! $error && $discount->fk_facture_line) { $error++; - setEventMessage($langs->trans("ErrorCantSplitAUsedDiscount"), 'errors'); + setEventMessages($langs->trans("ErrorCantSplitAUsedDiscount"), null, 'errors'); } if (! $error) { @@ -166,13 +166,13 @@ if ($action == 'setremise') else { $error++; - setEventMessage($soc->error, 'errors'); + setEventMessages($soc->error, $soc->errors, 'errors'); } } } else { - setEventMessage($langs->trans("ErrorFieldFormat",$langs->trans("NewGlobalDiscount")), 'errors'); + setEventMessages($langs->trans("ErrorFieldFormat",$langs->trans("NewGlobalDiscount")), null, 'errors'); } } @@ -194,7 +194,7 @@ if (GETPOST("action") == 'confirm_remove' && GETPOST("confirm")=='yes') } else { - setEventMessage($discount->error, 'errors'); + setEventMessages($discount->error, $discount->errors, 'errors'); $db->rollback(); } } @@ -216,7 +216,7 @@ if ($socid > 0) $object->fetch($socid); /* - * Affichage onglets + * Display tabs */ $head = societe_prepare_head($object); @@ -300,7 +300,7 @@ if ($socid > 0) } /* - * Liste remises fixes restant en cours (= liees a acune facture ni ligne de facture) + * Liste remises fixes restant en cours (= liees a aucune facture ni ligne de facture) */ $sql = "SELECT rc.rowid, rc.amount_ht, rc.amount_tva, rc.amount_ttc, rc.tva_tx,"; $sql.= " rc.datec as dc, rc.description,"; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index c53d1b793f3..645b50cb8bc 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -258,7 +258,7 @@ class ExtraFields if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname) && ! is_numeric($attrname)) { - if(is_array($param) and count($param) > 0) + if(is_array($param) && count($param) > 0) { $params = $this->db->escape(serialize($param)); } diff --git a/htdocs/core/lib/doc.lib.php b/htdocs/core/lib/doc.lib.php index 330d3d2ba39..76337ec2763 100644 --- a/htdocs/core/lib/doc.lib.php +++ b/htdocs/core/lib/doc.lib.php @@ -106,7 +106,7 @@ function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierli $ref_prodserv = ""; if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this { - if ($prodser->isservice()) + if ($prodser->isService()) { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." "; } diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 8e0eef6d53b..881415555bc 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1166,7 +1166,7 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl $ref_prodserv = ""; if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) // In standard mode, we do not show this { - if ($prodser->isservice()) + if ($prodser->isService()) { $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." "; } diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 69eb63717b2..d0bc74e77c3 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -98,7 +98,7 @@ function product_prepare_head($object) $head[$h][2] = 'referers'; $h++; - if ($object->isproduct() || ($object->isservice() && ! empty($conf->global->STOCK_SUPPORTS_SERVICES))) // If physical product we can stock (or service with option) + if ($object->isProduct() || ($object->isService() && ! empty($conf->global->STOCK_SUPPORTS_SERVICES))) // If physical product we can stock (or service with option) { if (! empty($conf->stock->enabled) && $user->rights->stock->lire) { diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index edb065c9d9b..ee70101318b 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -5,6 +5,7 @@ * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2014 Florian Henry * Copyright (C) 2014 Raphaël Doursenaud + * 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 @@ -315,14 +316,39 @@ else { service->enabled) || ($object->element == 'contrat')) && $dateSelector && GETPOST('type') != '0') // We show date field if required { - if(! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) $colspan = 10; - else $colspan = 9; - if($this->situation_cycle_ref) $colspan++; - if (! empty($inputalsopricewithtax)) $colspan++; // We add 1 if col total ttc - if (in_array($object->element,array('propal','askpricesupplier','facture','invoice','commande','order','order_supplier','invoice_supplier'))) $colspan++; // With this, there is a column move button + $colspan = 6; + + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { + $colspan++; + } + if ($this->situation_cycle_ref) { + $colspan++; + } + // We add 1 if col total ttc + if (!empty($inputalsopricewithtax)) { + $colspan++; + } if ($conf->global->PRODUCT_USE_UNITS) { $colspan++; } + if (count($object->lines)) { + //There will be an edit and a delete button + $colspan += 2; + + // With this, there is a column move button ONLY if lines > 1 + if (in_array($object->element, array( + 'propal', + 'askpricesupplier', + 'facture', + 'invoice', + 'commande', + 'order', + 'order_supplier', + 'invoice_supplier' + ))) { + $colspan++; + } + } if (! empty($usemargins)) { diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index 4252e4a9ef6..a46c5e6ca38 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -273,7 +273,7 @@ if ($resql) if ($search_all) { foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - print $langs->trans("FilterOnInto", $search_all, join(', ',$fieldstosearchall)); + print $langs->transnoentities("FilterOnInto", $search_all, join(', ',$fieldstosearchall)); } print ''; diff --git a/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql b/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql index 16e8a624e72..b728702db79 100644 --- a/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql +++ b/htdocs/install/mysql/tables/llx_opensurvey_sondage.sql @@ -29,5 +29,5 @@ CREATE TABLE llx_opensurvey_sondage ( allow_comments tinyint NOT NULL DEFAULT 1, allow_spy tinyint NOT NULL DEFAULT 1, tms TIMESTAMP, - sujet TEXT, -- Not filled if format = 'F'. Question are into table llx_opensurvey_formquestions + sujet TEXT -- Not filled if format = 'F'. Question are into table llx_opensurvey_formquestions ) ENGINE=InnoDB; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index a7291cc1895..4c30691318f 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1038,7 +1038,7 @@ else require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $type = $langs->trans('Product'); - if ($object->isservice()) $type = $langs->trans('Service'); + if ($object->isService()) $type = $langs->trans('Service'); //print load_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), ""); // Main official, simple, and not duplicated code @@ -1144,7 +1144,7 @@ else // Stock /* - if ($object->isproduct() && ! empty($conf->stock->enabled)) + if ($object->isProduct() && ! empty($conf->stock->enabled)) { print "".''; } - if ($object->isservice()) + if ($object->isService()) { // Duration print ''; } - if ($object->isservice()) + if ($object->isService()) { // Duration print '"; $nblignes=6; - if ($object->isproduct() && ! empty($conf->stock->enabled)) $nblignes++; - if ($object->isservice()) $nblignes++; + if ($object->isProduct() && ! empty($conf->stock->enabled)) $nblignes++; + if ($object->isService()) $nblignes++; // Reference print '
'.$langs->trans("StockLimit").''; print ''; @@ -1169,7 +1169,7 @@ else print '
'.$langs->trans("Duration").''; @@ -1435,7 +1435,7 @@ else print '
'.$langs->trans("Duration").''.$object->duration_value.' '; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 4594baab7a2..64068652ca9 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3804,7 +3804,7 @@ class Product extends CommonObject * * @return boolean True if it's a product */ - function isproduct() + function isProduct() { return ($this->type == Product::TYPE_PRODUCT ? true : false); } @@ -3814,7 +3814,7 @@ class Product extends CommonObject * * @return boolean True if it's a service */ - function isservice() + function isService() { return ($this->type == Product::TYPE_SERVICE ? true : false); } @@ -4088,4 +4088,19 @@ class Product extends CommonObject return 1; } + + /** + * Returns the rights used for this class + * @return stdClass + */ + public function getRights() + { + global $user; + + if ($this->isProduct()) { + return $user->rights->produit; + } else { + return $user->rights->service; + } + } } diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php index 276356d8bca..86dfb8a8fd4 100644 --- a/htdocs/product/composition/card.php +++ b/htdocs/product/composition/card.php @@ -193,8 +193,8 @@ if ($id > 0 || ! empty($ref)) print "
'.$langs->trans("Ref").''; diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index dfbd5679ac4..96aa9aa6311 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -521,7 +521,7 @@ if ($id > 0 || $ref) { // Suppliers list title print ''; - if ($object->isproduct()) $nblignefour=4; + if ($object->isProduct()) $nblignefour=4; else $nblignefour=4; $param="&id=".$object->id; diff --git a/htdocs/product/price.php b/htdocs/product/price.php index e1e1eeab0fe..497f676ae8c 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -113,86 +113,115 @@ if (empty($reshook)) $action=''; } - if (($action == 'update_price') && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) + if (($action == 'update_price') && !$cancel && $object->getRights()->creer) { - $newprice = ''; - $newprice_min = ''; - $newpricebase = ''; - $newvat = ''; - + $error = 0; + $pricestoupdate = array(); + + $psq = GETPOST('psqflag'); + $psq = empty($newpsq) ? 0 : $newpsq; $maxpricesupplier = $object->min_recommended_price(); - $object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression - // MultiPrix - if (!empty($conf->global->PRODUIT_MULTIPRICES)) { - - //Shall we generate prices using price rules? - $object->price_autogen = GETPOST('usePriceRules') == 'on' ? true : false; - $object->update($object->id, $user); - - for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) { - if (isset($_POST ["price_".$i])) { - $level = $i; - $newprice = price2num($_POST ["price_".$i], 'MU'); - $newprice_min = price2num($_POST ["price_min_".$i], 'MU'); - $newpricebase = $_POST ["multiprices_base_type_".$i]; - $newnpr = (preg_match('/\*/', $_POST ["tva_tx_".$i]) ? 1 : 0); - $newvat = str_replace('*', '', $_POST ["tva_tx_".$i]); - $newpsq = GETPOST('psqflag'); - $newpsq = empty($newpsq) ? 0 : $newpsq; - break; // We found submited price - } - } - } else { - $level = 0; - $newprice = price2num($_POST ["price"], 'MU'); - $newprice_min = price2num($_POST ["price_min"], 'MU'); - $newpricebase = $_POST ["price_base_type"]; - $newnpr = (preg_match('/\*/', $_POST ["tva_tx"]) ? 1 : 0); - $newvat = str_replace('*', '', $_POST ["tva_tx"]); - $newpsq = GETPOST('psqflag'); - $newpsq = empty($newpsq) ? 0 : $newpsq; - } - - if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $newprice_min < $maxpricesupplier) { - setEventMessage($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, - 1, - 1, 'auto')), 'errors'); - $error ++; - $action = 'edit_price'; - } - - if ($newprice < $newprice_min && !empty($object->fk_price_expression)) { - $newprice = $newprice_min; //Set price same as min, the user will not see the - } - - $res = $object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq); - - if ($res) { + if (!empty($conf->dynamicprices->enabled)) { + $object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression if ($object->fk_price_expression != 0) { //Check the expression validity by parsing it $priceparser = new PriceParser($db); - $price_result = $priceparser->parseProduct($object); - if ($price_result < 0) { //Expression is not valid + + if ($priceparser->parseProduct($object) < 0) { $error ++; - $action = 'edit_price'; setEventMessage($priceparser->translatedError(), 'errors'); } } - if (empty($error) && !empty($conf->dynamicprices->enabled)) { - $ret = $object->setPriceExpression($object->fk_price_expression); - if ($ret < 0) { - $error ++; - $action = 'edit_price'; - setEventMessage($object->error, 'errors'); + } + + // Multiprices + if (!$error && !empty($conf->global->PRODUIT_MULTIPRICES)) { + + $newprice = GETPOST('price', 'array'); + $newprice_min = GETPOST('price_min', 'array'); + $newpricebase = GETPOST('multiprices_base_type', 'array'); + $newvattx = GETPOST('tva_tx', 'array'); + + //Shall we generate prices using price rules? + $object->price_autogen = GETPOST('usePriceRules') == 'on' ? true : false; + + for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) { + + if (!isset($newprice[$i])) { + continue; + } + + $newnpr = (preg_match('/\*/', $newvattx[$i] ? 1 : 0)); + $newvat = str_replace('*', '', $newvattx[$i]); + + $pricestoupdate[$i] = array( + 'price' => $newprice[$i], + 'price_min' => $newprice_min[$i], + 'price_base_type' => $newpricebase[$i], + 'vat_tx' => $newvat, + 'npr' => $newnpr + ); + + //If autogeneration is enabled, then we only set the first level + if ($object->price_autogen) { + break; } } - if (empty($error)) { - $action = ''; - setEventMessage($langs->trans("RecordSaved")); + } else { + $pricestoupdate[0] = array( + 'price' => $_POST ["price"], + 'price_min' => $_POST ["price_min"], + 'price_base_type' => $_POST ["price_base_type"], + 'vat_tx' => str_replace('*', '', $_POST ["tva_tx"]), + 'npr' => preg_match('/\*/', $_POST ["tva_tx"]) ? 1 : 0 + ); + } + + if (!$error && $object->update($object->id, $user) < 1) { + $error++; + setEventMessage($object->error, 'errors'); + $action = 'edit_price'; + } + + if (!$error) { + $db->begin(); + + foreach ($pricestoupdate as $key => $val) { + + $newprice = $val['price']; + + if ($val['price'] < $val['price_min'] && !empty($object->fk_price_expression)) { + $newprice = $val['price_min']; //Set price same as min, the user will not see the + } + + $newprice = price2num($newprice, 'MU'); + $newprice_min = price2num($val['price_min'], 'MU'); + + if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $newprice_min < $maxpricesupplier) { + setEventMessage($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, - 1, - 1, 'auto')), 'errors'); + $error ++; + break; + } + + $res = $object->updatePrice($newprice, $val['price_base_type'], $user, $val['vat_tx'], $newprice_min, $key, $val['npr'], $psq); + + if ($res < 0) { + $error ++; + setEventMessage($object->error, 'errors'); + break; + } } + } + + if (empty($error)) { + $action = ''; + setEventMessage($langs->trans("RecordSaved")); + $db->commit(); } else { $action = 'edit_price'; - setEventMessage($object->error, 'errors'); + $db->rollback(); } } @@ -423,13 +452,13 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) // Selling price print ''; print ''; if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility { // TVA - print ''; + print ''; } else { @@ -482,28 +511,28 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) if (! empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel); print ''; - if ($object->multiprices_base_type ["$i"] == 'TTC') { - print '';; + if ($object->multiprices_base_type[$i]) { + print ' '.$langs->trans($object->multiprices_base_type [$i]).''; } else { - print ' '.$langs->trans($object->price_base_type).'';; + print ' '.$langs->trans($object->price_base_type).''; } // Prix min print ''; @@ -877,7 +906,7 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> id . '" method="POST">'; + for($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++) { - - print ''; - if ($i > 1) print '
'; + + if ($i > 1) print '
'; elseif (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($conf->global->PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL)) { print $langs->trans('UseMultipriceRules'). ' price_autogen ? 'checked' : '').'>

'; } @@ -910,7 +940,7 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> print ''; if (empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) { - print ''; + print ''; } print '
' . $langs->trans("SellingPrice") . ''; - if ($object->multiprices_base_type["$soc->price_level"] == 'TTC') { - print price($object->multiprices_ttc["$soc->price_level"]); + if ($object->multiprices_base_type[$soc->price_level] == 'TTC') { + print price($object->multiprices_ttc[$soc->price_level]); } else { - print price($object->multiprices["$soc->price_level"]); + print price($object->multiprices[$soc->price_level]); } - if ($object->multiprices_base_type["$soc->price_level"]) { - print ' ' . $langs->trans($object->multiprices_base_type["$soc->price_level"]); + if ($object->multiprices_base_type[$soc->price_level]) { + print ' ' . $langs->trans($object->multiprices_base_type[$soc->price_level]); } else { print ' ' . $langs->trans($object->price_base_type); } @@ -437,18 +466,18 @@ if (! empty($conf->global->PRODUIT_MULTIPRICES)) // Price min print '
' . $langs->trans("MinPrice") . ''; - if ($object->multiprices_base_type["$soc->price_level"] == 'TTC') + if ($object->multiprices_base_type[$soc->price_level] == 'TTC') { - print price($object->multiprices_min_ttc["$soc->price_level"]) . ' ' . $langs->trans($object->multiprices_base_type["$soc->price_level"]); + print price($object->multiprices_min_ttc[$soc->price_level]) . ' ' . $langs->trans($object->multiprices_base_type[$soc->price_level]); } else { - print price($object->multiprices_min["$soc->price_level"]) . ' ' . $langs->trans(empty($object->multiprices_base_type["$soc->price_level"])?'HT':$object->multiprices_base_type["$soc->price_level"]); + print price($object->multiprices_min[$soc->price_level]) . ' ' . $langs->trans(empty($object->multiprices_base_type[$soc->price_level])?'HT':$object->multiprices_base_type[$soc->price_level]); } print '
' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx["$soc->price_level"], true) . '
' . $langs->trans("VATRate") . '' . vatrate($object->multiprices_tva_tx[$soc->price_level], true) . '
' . price($object->multiprices_ttc["$i"]); + if ($object->multiprices_base_type [$i] == 'TTC') { + print '' . price($object->multiprices_ttc[$i]); } else { - print '' . price($object->multiprices["$i"]); + print '' . price($object->multiprices[$i]); } - if ($object->multiprices_base_type["$i"]) { - print ' '.$langs->trans($object->multiprices_base_type ["$i"]).''; - if (empty($object->multiprices_base_type["$i"])) $object->multiprices_base_type["$i"]="HT"; - if ($object->multiprices_base_type["$i"] == 'TTC') + if (empty($object->multiprices_base_type[$i])) $object->multiprices_base_type[$i]="HT"; + if ($object->multiprices_base_type[$i] == 'TTC') { - print price($object->multiprices_min_ttc["$i"]) . ' ' . $langs->trans($object->multiprices_base_type["$i"]); + print price($object->multiprices_min_ttc[$i]) . ' ' . $langs->trans($object->multiprices_base_type[$i]); } else { - print price($object->multiprices_min["$i"]) . ' ' . $langs->trans($object->multiprices_base_type["$i"]); + print price($object->multiprices_min[$i]) . ' ' . $langs->trans($object->multiprices_base_type[$i]); } print '
'; @@ -919,7 +949,7 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // This option is kept for backward compatibility but has no sense { print ''; } @@ -928,22 +958,22 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> $text = $langs->trans('SellingPrice') . ' ' . $i; print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); print ''; // Min price print ''; - print ''; - print '
' . $langs->trans("VATRate") . ''; - print $form->load_tva("tva_tx_" . $i, $object->multiprices_tva_tx["$i"], $mysoc, '', $object->id); + print $form->load_tva("tva_tx[" . $i.']', $object->multiprices_tva_tx[$i], $mysoc, '', $object->id); print '
'; - if ($object->multiprices_base_type ["$i"] == 'TTC') { - print ''; + if ($object->multiprices_base_type [$i] == 'TTC') { + print ''; } else { - print ''; + print ''; } - print $form->selectPriceBaseType($object->multiprices_base_type ["$i"], "multiprices_base_type_" . $i); + print ' '.$form->selectPriceBaseType($object->multiprices_base_type [$i], "multiprices_base_type[" . $i."]"); print '
'; $text = $langs->trans('MinPrice') . ' ' . $i; print $form->textwithpicto($text, $langs->trans("PrecisionUnitIsLimitedToXDecimals", $conf->global->MAIN_MAX_DECIMALS_UNIT), 1, 1); - if ($object->multiprices_base_type ["$i"] == 'TTC') { - print ''; + if ($object->multiprices_base_type [$i] == 'TTC') { + print ''; } else { - print ''; + print ''; } if ( !empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) { @@ -951,15 +981,16 @@ if ($action == 'edit_price' && ($user->rights->produit->creer || $user->rights-> } print '
'; - print '   '; - print '
'; - print ''; } - + + print '
'; + print ''; + print '   '; + print '
'; + print ''; + dol_fiche_end(); } } diff --git a/htdocs/public/paybox/newpayment.php b/htdocs/public/paybox/newpayment.php index 42ea013eade..481fd17f049 100644 --- a/htdocs/public/paybox/newpayment.php +++ b/htdocs/public/paybox/newpayment.php @@ -583,7 +583,7 @@ if (GETPOST("source") == 'contractline' && $valid) $duration=''; if ($contractline->fk_product) { - if ($product->isservice() && $product->duration_value > 0) + if ($product->isService() && $product->duration_value > 0) { $label=$langs->trans("Duration"); diff --git a/htdocs/public/paypal/newpayment.php b/htdocs/public/paypal/newpayment.php index 23f81c4295b..dcb43c07170 100644 --- a/htdocs/public/paypal/newpayment.php +++ b/htdocs/public/paypal/newpayment.php @@ -720,7 +720,7 @@ if (GETPOST("source") == 'contractline' && $valid) $duration=''; if ($contractline->fk_product) { - if ($product->isservice() && $product->duration_value > 0) + if ($product->isService() && $product->duration_value > 0) { $label=$langs->trans("Duration");