diff --git a/htdocs/fourn/ajax/getSupplierPrices.php b/htdocs/fourn/ajax/getSupplierPrices.php index 0c0d8f42c9e..e0cd9beff0c 100644 --- a/htdocs/fourn/ajax/getSupplierPrices.php +++ b/htdocs/fourn/ajax/getSupplierPrices.php @@ -22,10 +22,18 @@ * \brief File to return an Ajax response to get list of possible prices for margin calculation */ -if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal -if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); -if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); // Disables token renewal +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (!defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; @@ -46,47 +54,45 @@ top_httphead(); //print ''."\n"; -if ($idprod > 0) -{ +if ($idprod > 0) { $producttmp = new ProductFournisseur($db); $producttmp->fetch($idprod); $sorttouse = 's.nom, pfp.quantity, pfp.price'; - if (GETPOST('bestpricefirst')) $sorttouse = 'pfp.unitprice, s.nom, pfp.quantity, pfp.price'; + if (GETPOST('bestpricefirst')) { + $sorttouse = 'pfp.unitprice, s.nom, pfp.quantity, pfp.price'; + } $productSupplierArray = $producttmp->list_product_fournisseur_price($idprod, $sorttouse); // We list all price per supplier, and then firstly with the lower quantity. So we can choose first one with enough quantity into list. - if (is_array($productSupplierArray)) - { - foreach ($productSupplierArray as $productSupplier) - { + if (is_array($productSupplierArray)) { + foreach ($productSupplierArray as $productSupplier) { $price = $productSupplier->fourn_price * (1 - $productSupplier->fourn_remise_percent / 100); $unitprice = $productSupplier->fourn_unitprice * (1 - $productSupplier->fourn_remise_percent / 100); $title = $productSupplier->fourn_name.' - '.$productSupplier->fourn_ref.' - '; - if ($productSupplier->fourn_qty == 1) - { + if ($productSupplier->fourn_qty == 1) { $title .= price($price, 0, $langs, 0, 0, -1, $conf->currency)."/"; } $title .= $productSupplier->fourn_qty.' '.($productSupplier->fourn_qty == 1 ? $langs->trans("Unit") : $langs->trans("Units")); - if ($productSupplier->fourn_qty > 1) - { + if ($productSupplier->fourn_qty > 1) { $title .= " - "; $title .= price($unitprice, 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit"); $price = $unitprice; } $label = price($price, 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit"); - if ($productSupplier->fourn_ref) $label .= ' ('.$productSupplier->fourn_ref.')'; + if ($productSupplier->fourn_ref) { + $label .= ' ('.$productSupplier->fourn_ref.')'; + } $prices[] = array("id" => $productSupplier->product_fourn_price_id, "price" => price2num($price, 0, '', 0), "label" => $label, "title" => $title); // For price field, we must use price2num(), for label or title, price() } } // After best supplier prices and before costprice - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { // Add price for pmp $price = $producttmp->pmp; $prices[] = array("id" => 'pmpprice', "price" => price2num($price), "label" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency), "title" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency)); // For price field, we must use price2num(), for label or title, price() diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 418773daec5..1d7f5cce418 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -36,8 +36,12 @@ require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; -if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; -if (!empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +if (!empty($conf->adherent->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; +} +if (!empty($conf->categorie->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +} // Load translation files required by page $langs->loadLangs(array( @@ -54,7 +58,9 @@ $cancelbutton = GETPOST('cancel', 'alpha'); // Security check $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int')); -if ($user->socid) $id = $user->socid; +if ($user->socid) { + $id = $user->socid; +} $result = restrictedArea($user, 'societe&fournisseur', $id, '&societe', '', 'rowid'); $object = new Fournisseur($db); @@ -82,44 +88,48 @@ if ($object->id > 0) { $parameters = array('id'=>$id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ - if ($cancelbutton) - { +if (empty($reshook)) { + if ($cancelbutton) { $action = ""; } - if ($action == 'setsupplieraccountancycode') - { + if ($action == 'setsupplieraccountancycode') { $result = $object->fetch($id); - $object->code_compta_fournisseur = $_POST["supplieraccountancycode"]; + $object->code_compta_fournisseur = $_POST["supplieraccountancycode"]; $result = $object->update($object->id, $user, 1, 0, 1); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // terms of the settlement - if ($action == 'setconditions' && $user->rights->societe->creer) - { + if ($action == 'setconditions' && $user->rights->societe->creer) { $object->fetch($id); $result = $object->setPaymentTerms(GETPOST('cond_reglement_supplier_id', 'int')); - if ($result < 0) dol_print_error($db, $object->error); + if ($result < 0) { + dol_print_error($db, $object->error); + } } // mode de reglement - if ($action == 'setmode' && $user->rights->societe->creer) - { + if ($action == 'setmode' && $user->rights->societe->creer) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_supplier_id', 'int')); - if ($result < 0) dol_print_error($db, $object->error); + if ($result < 0) { + dol_print_error($db, $object->error); + } } // update supplier order min amount - if ($action == 'setsupplier_order_min_amount') - { + if ($action == 'setsupplier_order_min_amount') { $object->fetch($id); $object->supplier_order_min_amount = price2num(GETPOST('supplier_order_min_amount', 'alpha')); $result = $object->update($object->id, $user); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } if ($action == 'update_extras') { @@ -130,15 +140,20 @@ if (empty($reshook)) // Fill array 'array_options' with data from update form $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) $error++; - - if (!$error) - { - $result = $object->insertExtraFields('COMPANY_MODIFY'); - if ($result < 0) $error++; + if ($ret < 0) { + $error++; } - if ($error) $action = 'edit_extras'; + if (!$error) { + $result = $object->insertExtraFields('COMPANY_MODIFY'); + if ($result < 0) { + $error++; + } + } + + if ($error) { + $action = 'edit_extras'; + } } } @@ -150,17 +165,19 @@ if (empty($reshook)) $contactstatic = new Contact($db); $form = new Form($db); -if ($id > 0 && empty($object->id)) -{ +if ($id > 0 && empty($object->id)) { // Load data of third party $res = $object->fetch($id); - if ($object->id <= 0) dol_print_error($db, $object->error); + if ($object->id <= 0) { + dol_print_error($db, $object->error); + } } -if ($object->id > 0) -{ +if ($object->id > 0) { $title = $langs->trans("ThirdParty")." - ".$langs->trans('Supplier'); - if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$langs->trans('Supplier'); + if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { + $title = $object->name." - ".$langs->trans('Supplier'); + } $help_url = ''; llxHeader('', $title, $help_url); @@ -185,22 +202,20 @@ if ($object->id > 0) print $object->getTypeUrl(1); print ''; - if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field - { + if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field print ''.$langs->trans('Prefix').''.$object->prefix_comm.''; } - if ($object->fournisseur) - { + if ($object->fournisseur) { print ''; - print ''.$langs->trans("SupplierCode").''; - print $object->code_fournisseur; - $tmpcheck = $object->check_codefournisseur(); - if ($tmpcheck != 0 && $tmpcheck != -5) { - print ' ('.$langs->trans("WrongSupplierCode").')'; - } - print ''; - print ''; + print ''.$langs->trans("SupplierCode").''; + print $object->code_fournisseur; + $tmpcheck = $object->check_codefournisseur(); + if ($tmpcheck != 0 && $tmpcheck != -5) { + print ' ('.$langs->trans("WrongSupplierCode").')'; + } + print ''; + print ''; $langs->load('compta'); print ''; @@ -222,14 +237,12 @@ if ($object->id > 0) print ''; // Local Taxes - if ($mysoc->useLocalTax(1)) - { + if ($mysoc->useLocalTax(1)) { print ''.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; print yn($object->localtax1_assuj); print ''; } - if ($mysoc->useLocalTax(2)) - { + if ($mysoc->useLocalTax(2)) { print ''.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; print yn($object->localtax2_assuj); print ''; @@ -247,11 +260,12 @@ if ($object->id > 0) print ''; + if (($action != 'editconditions') && $user->rights->societe->creer) { + print ''; + } print '
'; print $langs->trans('PaymentConditions'); print ''; - if (($action != 'editconditions') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetConditions'), 1).'id.'">'.img_edit($langs->trans('SetConditions'), 1).'
'; print ''; - if ($action == 'editconditions') - { + if ($action == 'editconditions') { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'cond_reglement_supplier_id', -1, 1); } else { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_supplier_id, 'none'); @@ -264,11 +278,12 @@ if ($object->id > 0) print ''; + if (($action != 'editmode') && $user->rights->societe->creer) { + print ''; + } print '
'; print $langs->trans('PaymentMode'); print ''; - if (($action != 'editmode') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetMode'), 1).'id.'">'.img_edit($langs->trans('SetMode'), 1).'
'; print ''; - if ($action == 'editmode') - { + if ($action == 'editmode') { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_supplier_id, 'mode_reglement_supplier_id', 'DBIT', 1, 1); } else { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_supplier_id, 'none'); @@ -281,8 +296,7 @@ if ($object->id > 0) print '
'; print $langs->trans("CustomerRelativeDiscountShort"); print ''; - if ($user->rights->societe->creer && !$user->socid > 0) - { + if ($user->rights->societe->creer && !$user->socid > 0) { print ''.img_edit($langs->trans("Modify")).''; } print '
'; @@ -295,22 +309,24 @@ if ($object->id > 0) print ''; print $langs->trans("CustomerAbsoluteDiscountShort"); print ''; - if ($user->rights->societe->creer && !$user->socid > 0) - { + if ($user->rights->societe->creer && !$user->socid > 0) { print ''.img_edit($langs->trans("Modify")).''; } print ''; print ''; print ''; $amount_discount = $object->getAvailableDiscounts('', '', 0, 1); - if ($amount_discount < 0) dol_print_error($db, $object->error); - if ($amount_discount > 0) print ''.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).''; + if ($amount_discount < 0) { + dol_print_error($db, $object->error); + } + if ($amount_discount > 0) { + print ''.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).''; + } //else print $langs->trans("DiscountNone"); print ''; print ''; - if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)) - { + if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)) { print ''; print ''; print $form->editfieldkey("OrderMinAmount", 'supplier_order_min_amount', $object->supplier_order_min_amount, $object, $user->rights->societe->creer); @@ -322,8 +338,7 @@ if ($object->id > 0) } // Categories - if (!empty($conf->categorie->enabled)) - { + if (!empty($conf->categorie->enabled)) { $langs->load("categories"); print ''.$langs->trans("SuppliersCategoriesShort").''; print ''; @@ -336,16 +351,14 @@ if ($object->id > 0) include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; // Module Adherent - if (!empty($conf->adherent->enabled)) - { + if (!empty($conf->adherent->enabled)) { $langs->load("members"); $langs->load("users"); print ''.$langs->trans("LinkedToDolibarrMember").''; print ''; $adh = new Adherent($db); $result = $adh->fetch('', '', $object->id); - if ($result > 0) - { + if ($result > 0) { $adh->ref = $adh->getFullName($langs); print $adh->getNomUrl(1); } else { @@ -372,8 +385,7 @@ if ($object->id > 0) $boxstat .= ''; $boxstat .= ''; print '
'; - if ($conf->supplier_proposal->enabled) - { + if ($conf->supplier_proposal->enabled) { // Box proposals $tmp = $object->getOutstandingProposals('supplier'); $outstandingOpened = $tmp['opened']; @@ -382,16 +394,19 @@ if ($object->id > 0) $text = $langs->trans("OverAllSupplierProposals"); $link = DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id; $icon = 'bill'; - if ($link) $boxstat .= ''; + if ($link) { + $boxstat .= ''; + } $boxstat .= '
'; $boxstat .= ''.img_object("", $icon).' '.$text.'
'; $boxstat .= ''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; $boxstat .= '
'; - if ($link) $boxstat .= '
'; + if ($link) { + $boxstat .= ''; + } } - if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) - { + if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) { // Box proposals $tmp = $object->getOutstandingOrders('supplier'); $outstandingOpened = $tmp['opened']; @@ -400,16 +415,19 @@ if ($object->id > 0) $text = $langs->trans("OverAllOrders"); $link = DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id; $icon = 'bill'; - if ($link) $boxstat .= ''; + if ($link) { + $boxstat .= ''; + } $boxstat .= '
'; $boxstat .= ''.img_object("", $icon).' '.$text.'
'; $boxstat .= ''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; $boxstat .= '
'; - if ($link) $boxstat .= '
'; + if ($link) { + $boxstat .= ''; + } } - if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) - { + if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) { $tmp = $object->getOutstandingBills('supplier'); $outstandingOpened = $tmp['opened']; $outstandingTotal = $tmp['total_ht']; @@ -418,23 +436,31 @@ if ($object->id > 0) $text = $langs->trans("OverAllInvoices"); $link = DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id; $icon = 'bill'; - if ($link) $boxstat .= ''; + if ($link) { + $boxstat .= ''; + } $boxstat .= '
'; $boxstat .= ''.img_object("", $icon).' '.$text.'
'; $boxstat .= ''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; $boxstat .= '
'; - if ($link) $boxstat .= '
'; + if ($link) { + $boxstat .= ''; + } // Box outstanding bill $text = $langs->trans("CurrentOutstandingBill"); $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id; $icon = 'bill'; - if ($link) $boxstat .= ''; + if ($link) { + $boxstat .= ''; + } $boxstat .= '
'; $boxstat .= ''.img_object("", $icon).' '.$text.'
'; $boxstat .= ''.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.''; $boxstat .= '
'; - if ($link) $boxstat .= '
'; + if ($link) { + $boxstat .= ''; + } $tmp = $object->getOutstandingBills('supplier', 1); $outstandingOpenedLate = $tmp['opened']; @@ -442,12 +468,16 @@ if ($object->id > 0) $text = $langs->trans("CurrentOutstandingBillLate"); $link = DOL_URL_ROOT.'/fourn/recap-fourn.php?socid='.$object->id; $icon = 'bill'; - if ($link) $boxstat .= ''; + if ($link) { + $boxstat .= ''; + } $boxstat .= '
'; $boxstat .= ''.img_object("", $icon).' '.$text.'
'; $boxstat .= ''.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.''; $boxstat .= '
'; - if ($link) $boxstat .= '
'; + if ($link) { + $boxstat .= ''; + } } } @@ -469,13 +499,12 @@ if ($object->id > 0) print '
'; print '
'; - */ + */ /* * List of products */ - if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) - { + if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { $langs->load("products"); //Query from product/liste.php $sql = 'SELECT p.rowid, p.ref, p.label, p.fk_product_type, p.entity,'; @@ -488,7 +517,9 @@ if ($object->id > 0) $sql .= $db->plimit($MAXLIST); $query = $db->query($sql); - if (!$query) dol_print_error($db); + if (!$query) { + dol_print_error($db); + } $num = $db->num_rows($query); @@ -499,12 +530,10 @@ if ($object->id > 0) print ''; $return = array(); - if ($num > 0) - { + if ($num > 0) { $productstatic = new Product($db); - while ($objp = $db->fetch_object($query)) - { + while ($objp = $db->fetch_object($query)) { $productstatic->id = $objp->rowid; $productstatic->ref = $objp->ref; $productstatic->label = $objp->label; @@ -524,11 +553,9 @@ if ($object->id > 0) //print ''.dol_print_date($objp->tms, 'day').''; print ''; //print (isset($objp->unitprice) ? price($objp->unitprice) : ''); - if (isset($objp->price)) - { + if (isset($objp->price)) { print price($objp->price); - if ($objp->quantity > 1) - { + if ($objp->quantity > 1) { print ' / '; print $objp->quantity; } @@ -547,8 +574,7 @@ if ($object->id > 0) */ $proposalstatic = new SupplierProposal($db); - if ($user->rights->supplier_proposal->lire) - { + if ($user->rights->supplier_proposal->lire) { $langs->loadLangs(array("supplier_proposal")); $sql = "SELECT p.rowid, p.ref, p.date_valid as dc, p.fk_statut, p.total_ht, p.total_tva, p.total_ttc"; @@ -559,13 +585,11 @@ if ($object->id > 0) $sql .= " ".$db->plimit($MAXLIST); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $i = 0; $num = $db->num_rows($resql); - if ($num > 0) - { + if ($num > 0) { print ''; print ''; @@ -577,8 +601,7 @@ if ($object->id > 0) print ''; } - while ($i < $num && $i <= $MAXLIST) - { + while ($i < $num && $i <= $MAXLIST) { $obj = $db->fetch_object($resql); print ''; @@ -591,8 +614,7 @@ if ($object->id > 0) print $proposalstatic->getNomUrl(1); print ''; print '
'; - if ($obj->dc) - { + if ($obj->dc) { print dol_print_date($db->jdate($obj->dc), 'day'); } else { print "-"; @@ -604,7 +626,9 @@ if ($object->id > 0) } $db->free($resql); - if ($num > 0) print "
"; + if ($num > 0) { + print ""; + } } else { dol_print_error($db); } @@ -615,8 +639,7 @@ if ($object->id > 0) */ $orderstatic = new CommandeFournisseur($db); - if ($user->rights->fournisseur->commande->lire) - { + if ($user->rights->fournisseur->commande->lire) { // TODO move to DAO class // Check if there are supplier orders billable $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,'; @@ -627,8 +650,7 @@ if ($object->id > 0) $sql2 .= " AND c.entity IN (".getEntity('commande_fournisseur').")"; $sql2 .= ' AND s.rowid = '.$object->id; // Show orders we can bill - if (empty($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS)) - { + if (empty($conf->global->SUPPLIER_ORDER_TO_INVOICE_STATUS)) { $sql2 .= " AND c.fk_statut IN (".$db->sanitize(CommandeFournisseur::STATUS_RECEIVED_COMPLETELY).")"; // Must match filter in htdocs/fourn/commande/list.php } else { // CommandeFournisseur::STATUS_ORDERSENT.", ".CommandeFournisseur::STATUS_RECEIVED_PARTIALLY.", ".CommandeFournisseur::STATUS_RECEIVED_COMPLETELY @@ -652,8 +674,7 @@ if ($object->id > 0) $sql .= " WHERE p.fk_soc =".$object->id; $sql .= " AND p.entity IN (".getEntity('commande_fournisseur').")"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $object_count = $db->fetch_object($resql); $num = $object_count->total; } @@ -665,12 +686,10 @@ if ($object->id > 0) $sql .= " ORDER BY p.date_commande DESC"; $sql .= " ".$db->plimit($MAXLIST); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $i = 0; - if ($num > 0) - { + if ($num > 0) { print ''; print ''; @@ -682,8 +701,7 @@ if ($object->id > 0) print ''; } - while ($i < $num && $i < $MAXLIST) - { + while ($i < $num && $i < $MAXLIST) { $obj = $db->fetch_object($resql); print ''; @@ -696,8 +714,7 @@ if ($object->id > 0) print $orderstatic->getNomUrl(1); print ''; print '
'; - if ($obj->dc) - { + if ($obj->dc) { print dol_print_date($db->jdate($obj->dc), 'day'); } else { print "-"; @@ -709,7 +726,9 @@ if ($object->id > 0) } $db->free($resql); - if ($num > 0) print "
"; + if ($num > 0) { + print ""; + } } else { dol_print_error($db); } @@ -722,8 +741,7 @@ if ($object->id > 0) $langs->load('bills'); $facturestatic = new FactureFournisseur($db); - if ($user->rights->fournisseur->facture->lire) - { + if ($user->rights->fournisseur->facture->lire) { // TODO move to DAO class $sql = 'SELECT f.rowid, f.libelle as label, f.ref, f.ref_supplier, f.fk_statut, f.datef as df, f.total_ht, f.total_tva, f.total_ttc as amount,f.paye,'; $sql .= ' SUM(pf.amount) as am'; @@ -734,12 +752,10 @@ if ($object->id > 0) $sql .= ' GROUP BY f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef,f.total_ht,f.total_tva,f.total_ttc,f.paye'; $sql .= ' ORDER BY f.datef DESC'; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $i = 0; $num = $db->num_rows($resql); - if ($num > 0) - { + if ($num > 0) { print ''; print ''; @@ -750,8 +766,7 @@ if ($object->id > 0) print ''; } - while ($i < min($num, $MAXLIST)) - { + while ($i < min($num, $MAXLIST)) { $obj = $db->fetch_object($resql); print ''; @@ -778,7 +793,9 @@ if ($object->id > 0) $i++; } $db->free($resql); - if ($num > 0) print '
'; + if ($num > 0) { + print ''; + } } else { dol_print_error($db); } @@ -798,15 +815,12 @@ if ($object->id > 0) $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook - if (empty($reshook)) - { - if ($object->status != 1) - { + if (empty($reshook)) { + if ($object->status != 1) { print '
'.$langs->trans("ThirdPartyIsClosed").'
'; } - if ($conf->supplier_proposal->enabled && $user->rights->supplier_proposal->creer) - { + if ($conf->supplier_proposal->enabled && $user->rights->supplier_proposal->creer) { $langs->load("supplier_proposal"); if ($object->status == 1) { print ''.$langs->trans("AddSupplierProposal").''; @@ -815,8 +829,7 @@ if ($object->id > 0) } } - if ($user->rights->fournisseur->commande->creer) - { + if ($user->rights->fournisseur->commande->creer) { $langs->load("orders"); if ($object->status == 1) { print ''.$langs->trans("AddOrder").''; @@ -825,21 +838,20 @@ if ($object->id > 0) } } - if ($user->rights->fournisseur->facture->creer) - { - if (!empty($orders2invoice) && $orders2invoice > 0) - { + if ($user->rights->fournisseur->facture->creer) { + if (!empty($orders2invoice) && $orders2invoice > 0) { if ($object->status == 1) { // Company is open print '
'.$langs->trans("CreateInvoiceForThisSupplier").'
'; } else { print '
'.$langs->trans("CreateInvoiceForThisCustomer").'
'; } - } else print '
trans("WithReceptionFinished").')').'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'
'; + } else { + print '
trans("WithReceptionFinished").')').'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'
'; + } } - if ($user->rights->fournisseur->facture->creer) - { + if ($user->rights->fournisseur->facture->creer) { $langs->load("bills"); if ($object->status == 1) { print ''.$langs->trans("AddBill").''; @@ -849,10 +861,8 @@ if ($object->id > 0) } // Add action - if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1) - { - if ($user->rights->agenda->myactions->create) - { + if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1) { + if ($user->rights->agenda->myactions->create) { print ''.$langs->trans("AddAction").''; } else { print ''.$langs->trans("AddAction").''; @@ -863,15 +873,13 @@ if ($object->id > 0) print ''; - if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) - { + if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_MAIN_CARD)) { print '
'; // List of contacts show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id); } - if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) - { + if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) { print load_fiche_titre($langs->trans("ActionsOnCompany"), '', ''); // List of todo actions diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php index 247434be7a8..953092120e4 100644 --- a/htdocs/fourn/class/api_supplier_invoices.class.php +++ b/htdocs/fourn/class/api_supplier_invoices.class.php @@ -34,7 +34,7 @@ class SupplierInvoices extends DolibarrApi * * @var array $FIELDS Mandatory fields, checked when create and update object */ - static $FIELDS = array( + public static $FIELDS = array( 'socid', ); @@ -109,20 +109,32 @@ class SupplierInvoices extends DolibarrApi // If the internal user must only see his customers, force searching by him $search_sale = 0; - if (!DolibarrApiAccess::$user->rights->societe->client->voir) $search_sale = DolibarrApiAccess::$user->id; + if (!DolibarrApiAccess::$user->rights->societe->client->voir) { + $search_sale = DolibarrApiAccess::$user->id; + } $sql = "SELECT t.rowid"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) - if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; + if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) { + $sql .= ", sc.fk_soc, sc.fk_user"; + } $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as t"; // We need this table joined to the select in order to filter by sale - if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= ' WHERE t.entity IN ('.getEntity('supplier_invoice').')'; - if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc"; - if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")"; - if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + if (!DolibarrApiAccess::$user->rights->societe->client->voir || $search_sale > 0) { + $sql .= " AND t.fk_soc = sc.fk_soc"; + } + if ($socids) { + $sql .= " AND t.fk_soc IN (".$socids.")"; + } + if ($search_sale > 0) { + $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + } // Filter by status if ($status == 'draft') { @@ -142,10 +154,8 @@ class SupplierInvoices extends DolibarrApi $sql .= " AND sc.fk_user = ".$search_sale; } // Add sql filters - if ($sqlfilters) - { - if (!DolibarrApi::_checkFilters($sqlfilters)) - { + if ($sqlfilters) { + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; @@ -154,8 +164,7 @@ class SupplierInvoices extends DolibarrApi $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { - if ($page < 0) - { + if ($page < 0) { $page = 0; } $offset = $limit * $page; @@ -168,8 +177,7 @@ class SupplierInvoices extends DolibarrApi $i = 0; $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $invoice_static = new FactureFournisseur($this->db); if ($invoice_static->fetch($obj->rowid)) { @@ -244,12 +252,15 @@ class SupplierInvoices extends DolibarrApi } foreach ($request_data as $field => $value) { - if ($field == 'id') continue; + if ($field == 'id') { + continue; + } $this->invoice->$field = $value; } - if ($this->invoice->update($id, DolibarrApiAccess::$user)) + if ($this->invoice->update($id, DolibarrApiAccess::$user)) { return $this->get($id); + } return false; } @@ -279,8 +290,7 @@ class SupplierInvoices extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - if ($this->invoice->delete(DolibarrApiAccess::$user) < 0) - { + if ($this->invoice->delete(DolibarrApiAccess::$user) < 0) { throw new RestException(500); } @@ -459,16 +469,14 @@ class SupplierInvoices extends DolibarrApi $paiement->note_public = $comment; $paiement_id = $paiement->create(DolibarrApiAccess::$user, ($closepaidinvoices == 'yes' ? 1 : 0)); // This include closing invoices - if ($paiement_id < 0) - { + if ($paiement_id < 0) { $this->db->rollback(); throw new RestException(400, 'Payment error : '.$paiement->error); } if (!empty($conf->banque->enabled)) { $result = $paiement->addPaymentToBank(DolibarrApiAccess::$user, 'payment_supplier', '(SupplierInvoicePayment)', $accountid, $chqemetteur, $chqbank); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); throw new RestException(400, 'Add payment to bank error : '.$paiement->error); } @@ -706,8 +714,9 @@ class SupplierInvoices extends DolibarrApi { $invoice = array(); foreach (SupplierInvoices::$FIELDS as $field) { - if (!isset($data[$field])) + if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); + } $invoice[$field] = $data[$field]; } return $invoice; diff --git a/htdocs/fourn/class/api_supplier_orders.class.php b/htdocs/fourn/class/api_supplier_orders.class.php index 254e577f2f2..895902b13b2 100644 --- a/htdocs/fourn/class/api_supplier_orders.class.php +++ b/htdocs/fourn/class/api_supplier_orders.class.php @@ -32,7 +32,7 @@ class SupplierOrders extends DolibarrApi * * @var array $FIELDS Mandatory fields, checked when create and update object */ - static $FIELDS = array( + public static $FIELDS = array( 'socid' ); @@ -108,41 +108,70 @@ class SupplierOrders extends DolibarrApi // If the internal user must only see his customers, force searching by him $search_sale = 0; - if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; + if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) { + $search_sale = DolibarrApiAccess::$user->id; + } $sql = "SELECT t.rowid"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { + $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + } $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as t"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + } - if (!empty($product_ids)) $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; // We need this table joined to the select in order to filter by product + if (!empty($product_ids)) { + $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; // We need this table joined to the select in order to filter by product + } $sql .= ' WHERE t.entity IN ('.getEntity('supplier_order').')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.fk_soc = sc.fk_soc"; - if (!empty($product_ids)) $sql .= " AND cd.fk_commande = t.rowid AND cd.fk_product IN (".$product_ids.")"; - if ($socids) $sql .= " AND t.fk_soc IN (".$socids.")"; - if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { + $sql .= " AND t.fk_soc = sc.fk_soc"; + } + if (!empty($product_ids)) { + $sql .= " AND cd.fk_commande = t.rowid AND cd.fk_product IN (".$product_ids.")"; + } + if ($socids) { + $sql .= " AND t.fk_soc IN (".$socids.")"; + } + if ($search_sale > 0) { + $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + } // Filter by status - if ($status == 'draft') $sql .= " AND t.fk_statut IN (0)"; - if ($status == 'validated') $sql .= " AND t.fk_statut IN (1)"; - if ($status == 'approved') $sql .= " AND t.fk_statut IN (2)"; - if ($status == 'running') $sql .= " AND t.fk_statut IN (3)"; - if ($status == 'received_start') $sql .= " AND t.fk_statut IN (4)"; - if ($status == 'received_end') $sql .= " AND t.fk_statut IN (5)"; - if ($status == 'cancelled') $sql .= " AND t.fk_statut IN (6,7)"; - if ($status == 'refused') $sql .= " AND t.fk_statut IN (9)"; + if ($status == 'draft') { + $sql .= " AND t.fk_statut IN (0)"; + } + if ($status == 'validated') { + $sql .= " AND t.fk_statut IN (1)"; + } + if ($status == 'approved') { + $sql .= " AND t.fk_statut IN (2)"; + } + if ($status == 'running') { + $sql .= " AND t.fk_statut IN (3)"; + } + if ($status == 'received_start') { + $sql .= " AND t.fk_statut IN (4)"; + } + if ($status == 'received_end') { + $sql .= " AND t.fk_statut IN (5)"; + } + if ($status == 'cancelled') { + $sql .= " AND t.fk_statut IN (6,7)"; + } + if ($status == 'refused') { + $sql .= " AND t.fk_statut IN (9)"; + } // Insert sale filter - if ($search_sale > 0) - { + if ($search_sale > 0) { $sql .= " AND sc.fk_user = ".$search_sale; } // Add sql filters - if ($sqlfilters) - { - if (!DolibarrApi::_checkFilters($sqlfilters)) - { + if ($sqlfilters) { + if (!DolibarrApi::_checkFilters($sqlfilters)) { throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; @@ -151,8 +180,7 @@ class SupplierOrders extends DolibarrApi $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { - if ($page < 0) - { + if ($page < 0) { $page = 0; } $offset = $limit * $page; @@ -161,13 +189,11 @@ class SupplierOrders extends DolibarrApi } $result = $this->db->query($sql); - if ($result) - { + if ($result) { $i = 0; $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $order_static = new CommandeFournisseur($this->db); if ($order_static->fetch($obj->rowid)) { @@ -207,13 +233,13 @@ class SupplierOrders extends DolibarrApi $this->order->date = dol_now(); } /* We keep lines as an array - if (isset($request_data["lines"])) { - $lines = array(); - foreach ($request_data["lines"] as $line) { - array_push($lines, (object) $line); - } - $this->order->lines = $lines; - }*/ + if (isset($request_data["lines"])) { + $lines = array(); + foreach ($request_data["lines"] as $line) { + array_push($lines, (object) $line); + } + $this->order->lines = $lines; + }*/ if ($this->order->create(DolibarrApiAccess::$user) < 0) { throw new RestException(500, "Error creating order", array_merge(array($this->order->error), $this->order->errors)); @@ -244,12 +270,15 @@ class SupplierOrders extends DolibarrApi } foreach ($request_data as $field => $value) { - if ($field == 'id') continue; + if ($field == 'id') { + continue; + } $this->order->$field = $value; } - if ($this->order->update($id, DolibarrApiAccess::$user)) + if ($this->order->update($id, DolibarrApiAccess::$user)) { return $this->get($id); + } return false; } @@ -368,8 +397,9 @@ class SupplierOrders extends DolibarrApi { $order = array(); foreach (SupplierOrders::$FIELDS as $field) { - if (!isset($data[$field])) + if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); + } $order[$field] = $data[$field]; } return $order; diff --git a/htdocs/fourn/class/fournisseur.class.php b/htdocs/fourn/class/fournisseur.class.php index 4ca073a38c7..57f6fa52d26 100644 --- a/htdocs/fourn/class/fournisseur.class.php +++ b/htdocs/fourn/class/fournisseur.class.php @@ -62,12 +62,10 @@ class Fournisseur extends Societe $sql .= " WHERE cf.fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num == 1) - { + if ($num == 1) { $row = $this->db->fetch_row($resql); $this->single_open_commande = $row[0]; @@ -91,8 +89,7 @@ class Fournisseur extends Societe $sql .= " AND pfp.fk_soc = ".$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); return $obj->nb; } else { @@ -116,8 +113,7 @@ class Fournisseur extends Societe $sql = "SELECT count(s.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$user->socid) - { + if (!$user->rights->societe->client->voir && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; $sql .= " WHERE sc.fk_user = ".$user->id; $clause = "AND"; @@ -126,10 +122,8 @@ class Fournisseur extends Societe $sql .= " AND s.entity IN (".getEntity('societe').")"; $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->nb["suppliers"] = $obj->nb; } $this->db->free($resql); @@ -158,8 +152,7 @@ class Fournisseur extends Societe dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { dol_syslog("Fournisseur::CreateCategory : Success"); return 0; } else { @@ -185,17 +178,19 @@ class Fournisseur extends Societe $sql = "SELECT s.rowid, s.nom as name"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$user->socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE s.fournisseur = 1"; $sql .= " AND s.entity IN (".getEntity('societe').")"; - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + if (!$user->rights->societe->client->voir && !$user->socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; + } $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $arr[$obj->rowid] = $obj->name; } } else { diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 52121d8c83d..d4e92fd8bf4 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -34,7 +34,9 @@ include_once DOL_DOCUMENT_ROOT.'/core/class/commonorder.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; +if (!empty($conf->productbatch->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; +} require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; /** @@ -303,7 +305,9 @@ class CommandeFournisseur extends CommonOrder global $conf; // Check parameters - if (empty($id) && empty($ref)) return -1; + if (empty($id) && empty($ref)) { + return -1; + } $sql = "SELECT c.rowid, c.entity, c.ref, ref_supplier, c.fk_soc, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.total_tva,"; $sql .= " c.localtax1, c.localtax2, "; @@ -324,18 +328,21 @@ class CommandeFournisseur extends CommonOrder $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_input_method as cm ON cm.rowid = c.fk_input_method"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; - if (empty($id)) $sql .= " WHERE c.entity IN (".getEntity('supplier_order').")"; - else $sql .= " WHERE c.rowid=".$id; + if (empty($id)) { + $sql .= " WHERE c.entity IN (".getEntity('supplier_order').")"; + } else { + $sql .= " WHERE c.rowid=".$id; + } - if ($ref) $sql .= " AND c.ref='".$this->db->escape($ref)."'"; + if ($ref) { + $sql .= " AND c.ref='".$this->db->escape($ref)."'"; + } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if (!$obj) - { + if (!$obj) { $this->error = 'Bill with id '.$id.' not found'; dol_syslog(get_class($this).'::fetch '.$this->error); return 0; @@ -409,14 +416,15 @@ class CommandeFournisseur extends CommonOrder // fetch optionals attributes and labels $this->fetch_optionals(); - if ($this->statut == 0) $this->brouillon = 1; + if ($this->statut == 0) { + $this->brouillon = 1; + } /* - * Lines - */ + * Lines + */ $result = $this->fetch_lines(); - if ($result < 0) - { + if ($result < 0) { return -1; } else { return 1; @@ -449,26 +457,28 @@ class CommandeFournisseur extends CommonOrder $sql .= " l.fk_unit,"; $sql .= " l.date_start, l.date_end,"; $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc'; - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $sql .= ", pfp.rowid as fk_pfp, pfp.packaging"; + } $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON l.fk_product = pfp.fk_product and l.ref = pfp.ref_fourn"; + } $sql .= " WHERE l.fk_commande = ".$this->id; - if ($only_product) $sql .= ' AND p.fk_product_type = 0'; + if ($only_product) { + $sql .= ' AND p.fk_product_type = 0'; + } $sql .= " ORDER BY l.rang, l.rowid"; //print $sql; dol_syslog(get_class($this)."::fetch get lines", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $this->db->fetch_object($result); $line = new CommandeFournisseurLigne($this->db); @@ -505,8 +515,7 @@ class CommandeFournisseur extends CommonOrder $line->ref_fourn = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since $line->ref_supplier = $objp->ref_supplier; // The supplier ref of price when product was added. May have change since - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) - { + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $line->fk_fournprice = $objp->fk_pfp; $line->packaging = $objp->packaging; } @@ -563,8 +572,7 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::valid"); $result = 0; if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->commande->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate))) - { + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate))) { $this->db->begin(); // Definition of supplier order numbering model name @@ -572,8 +580,7 @@ class CommandeFournisseur extends CommonOrder $soc->fetch($this->fourn_id); // Check if object has a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life - { + if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($soc); } else { $num = $this->ref; @@ -589,49 +596,46 @@ class CommandeFournisseur extends CommonOrder $sql .= " AND fk_statut = ".self::STATUS_DRAFT; $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { dol_print_error($this->db); $error++; } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_VALIDATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->oldref = $this->ref; // Rename directory if dir was a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref)) - { + if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'fournisseur/commande/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->fournisseur->commande->dir_output.'/'.$oldref; $dirdest = $conf->fournisseur->commande->dir_output.'/'.$newref; - if (!$error && file_exists($dirsource)) - { + if (!$error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest); - if (@rename($dirsource, $dirdest)) - { + if (@rename($dirsource, $dirdest)) { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref $listoffiles = dol_dir_list($conf->fournisseur->commande->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) - { + foreach ($listoffiles as $fileentry) { $dirsource = $fileentry['name']; $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); $dirsource = $fileentry['path'].'/'.$dirsource; @@ -643,15 +647,13 @@ class CommandeFournisseur extends CommonOrder } } - if (!$error) - { + if (!$error) { $result = 1; $this->statut = self::STATUS_VALIDATED; $this->ref = $num; } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -696,8 +698,11 @@ class CommandeFournisseur extends CommonOrder $this->statuts[0] = 'StatusSupplierOrderDraft'; $this->statuts[1] = 'StatusSupplierOrderValidated'; $this->statuts[2] = 'StatusSupplierOrderApproved'; - if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $this->statuts[3] = 'StatusSupplierOrderOnProcess'; - else $this->statuts[3] = 'StatusSupplierOrderOnProcessWithValidation'; + if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) { + $this->statuts[3] = 'StatusSupplierOrderOnProcess'; + } else { + $this->statuts[3] = 'StatusSupplierOrderOnProcessWithValidation'; + } $this->statuts[4] = 'StatusSupplierOrderReceivedPartially'; $this->statuts[5] = 'StatusSupplierOrderReceivedAll'; $this->statuts[6] = 'StatusSupplierOrderCanceled'; // Approved->Canceled @@ -737,7 +742,9 @@ class CommandeFournisseur extends CommonOrder if ($billed) { $billedtext = ' - '.$langs->trans("Billed"); } - if ($status == 5 && $billed) $statusClass = 'status6'; + if ($status == 5 && $billed) { + $statusClass = 'status6'; + } $statusLong = $langs->transnoentitiesnoconv($this->statuts[$status]).$billedtext; $statusShort = $langs->transnoentitiesnoconv($this->statutshort[$status]); @@ -792,19 +799,20 @@ class CommandeFournisseur extends CommonOrder $picto = 'order'; $url = DOL_URL_ROOT.'/fourn/commande/card.php?id='.$this->id; - if ($option !== 'nolink') - { + if ($option !== 'nolink') { // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { + $add_save_lastsearch_values = 1; + } + if ($add_save_lastsearch_values) { + $url .= '&save_lastsearch_values=1'; + } } $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowOrder"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } @@ -817,15 +825,17 @@ class CommandeFournisseur extends CommonOrder $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= $this->ref; + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= $this->ref; + } $result .= $linkend; - if ($addlinktonotes) - { + if ($addlinktonotes) { $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private); - if ($txttoshow) - { + if ($txttoshow) { $notetoshow = $langs->trans("ViewPrivateNote").':
'.dol_string_nohtmltag($txttoshow, 1); $result .= ' '; $result .= ''; @@ -853,8 +863,7 @@ class CommandeFournisseur extends CommonOrder global $db, $langs, $conf; $langs->load("orders"); - if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) - { + if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) { $mybool = false; $file = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER.'.php'; @@ -878,8 +887,7 @@ class CommandeFournisseur extends CommonOrder $obj = new $classname(); $numref = $obj->getNextValue($soc, $this); - if ($numref != "") - { + if ($numref != "") { return $numref; } else { $this->error = $obj->error; @@ -900,8 +908,7 @@ class CommandeFournisseur extends CommonOrder { $error = 0; - if ($this->billed) - { + if ($this->billed) { return 0; } @@ -910,18 +917,17 @@ class CommandeFournisseur extends CommonOrder $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; - if ($this->db->query($sql)) - { - if (!$error) - { + if ($this->db->query($sql)) { + if (!$error) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_CLASSIFY_BILLED', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->billed = 1; $this->db->commit(); @@ -955,8 +961,7 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::approve"); - if ($user->rights->fournisseur->commande->approuver) - { + if ($user->rights->fournisseur->commande->approuver) { $now = dol_now(); $this->db->begin(); @@ -966,8 +971,7 @@ class CommandeFournisseur extends CommonOrder $soc->fetch($this->fourn_id); // Check if object has a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life - { + if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($soc); } else { $num = $this->ref; @@ -980,14 +984,11 @@ class CommandeFournisseur extends CommonOrder $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; $sql .= " SET ref='".$this->db->escape($num)."',"; - if (empty($secondlevel)) // standard or first level approval - { + if (empty($secondlevel)) { // standard or first level approval $sql .= " date_approve='".$this->db->idate($now)."',"; $sql .= " fk_user_approve = ".$user->id; - if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $conf->global->MAIN_FEATURES_LEVEL > 0 && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) - { - if (empty($this->user_approve_id2)) - { + if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $conf->global->MAIN_FEATURES_LEVEL > 0 && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) { + if (empty($this->user_approve_id2)) { $movetoapprovestatus = false; // second level approval not done $comment = ' (first level)'; } @@ -996,67 +997,72 @@ class CommandeFournisseur extends CommonOrder { $sql .= " date_approve2='".$this->db->idate($now)."',"; $sql .= " fk_user_approve2 = ".$user->id; - if (empty($this->user_approve_id)) $movetoapprovestatus = false; // first level approval not done + if (empty($this->user_approve_id)) { + $movetoapprovestatus = false; // first level approval not done + } $comment = ' (second level)'; } // If double approval is required and first approval, we keep status to 1 = validated - if ($movetoapprovestatus) $sql .= ", fk_statut = ".self::STATUS_ACCEPTED; - else $sql .= ", fk_statut = ".self::STATUS_VALIDATED; + if ($movetoapprovestatus) { + $sql .= ", fk_statut = ".self::STATUS_ACCEPTED; + } else { + $sql .= ", fk_statut = ".self::STATUS_VALIDATED; + } $sql .= " WHERE rowid = ".$this->id; $sql .= " AND fk_statut = ".self::STATUS_VALIDATED; - if ($this->db->query($sql)) - { - if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT)) - { + if ($this->db->query($sql)) { + if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT)) { $result = $this->add_contact($user->id, 'SALESREPFOLL', 'internal', 1); - if ($result < 0 && $result != -2) // -2 means already exists - { + if ($result < 0 && $result != -2) { // -2 means already exists $error++; } } // If stock is incremented on validate order, we must increment it - if (!$error && $movetoapprovestatus && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) - { + if (!$error && $movetoapprovestatus && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); $cpt = count($this->lines); - for ($i = 0; $i < $cpt; $i++) - { + for ($i = 0; $i < $cpt; $i++) { // Product with reference - if ($this->lines[$i]->fk_product > 0) - { + if ($this->lines[$i]->fk_product > 0) { $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We decrement stock of product (and sub-products) $up_ht_disc = $this->lines[$i]->subprice; - if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); + if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) { + $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); + } $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("OrderApprovedInDolibarr", $this->ref)); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } unset($this->line); } } } - if (!$error) - { + if (!$error) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_APPROVE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->ref = $this->newref; - if ($movetoapprovestatus) $this->statut = self::STATUS_ACCEPTED; - else $this->statut = self::STATUS_VALIDATED; - if (empty($secondlevel)) // standard or first level approval - { + if ($movetoapprovestatus) { + $this->statut = self::STATUS_ACCEPTED; + } else { + $this->statut = self::STATUS_VALIDATED; + } + if (empty($secondlevel)) { // standard or first level approval $this->date_approve = $now; $this->user_approve_id = $user->id; } else // request a second level approval @@ -1096,26 +1102,24 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::refuse"); $result = 0; - if ($user->rights->fournisseur->commande->approuver) - { + if ($user->rights->fournisseur->commande->approuver) { $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = ".self::STATUS_REFUSED; $sql .= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { $result = 0; - if ($error == 0) - { + if ($error == 0) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_REFUSE', $user); - if ($result < 0) - { + if ($result < 0) { $error++; $this->db->rollback(); - } else $this->db->commit(); + } else { + $this->db->commit(); + } // End call triggers } } else { @@ -1148,8 +1152,7 @@ class CommandeFournisseur extends CommonOrder //dol_syslog("CommandeFournisseur::Cancel"); $result = 0; - if ($user->rights->fournisseur->commande->commander) - { + if ($user->rights->fournisseur->commande->commander) { $statut = self::STATUS_CANCELED; $this->db->begin(); @@ -1157,17 +1160,17 @@ class CommandeFournisseur extends CommonOrder $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur SET fk_statut = ".$statut; $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::cancel", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { $result = 0; // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_CANCEL', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers - if ($error == 0) - { + if ($error == 0) { $this->db->commit(); return 1; } else { @@ -1200,12 +1203,13 @@ class CommandeFournisseur extends CommonOrder global $langs; dol_syslog(get_class($this)."::commande"); $error = 0; - if ($user->rights->fournisseur->commande->commander) - { + if ($user->rights->fournisseur->commande->commander) { $this->db->begin(); $newnoteprivate = $this->note_private; - if ($comment) $newnoteprivate = dol_concatdesc($newnoteprivate, $langs->trans("Comment").': '.$comment); + if ($comment) { + $newnoteprivate = dol_concatdesc($newnoteprivate, $langs->trans("Comment").': '.$comment); + } $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; $sql .= " SET fk_statut=".self::STATUS_ORDERSENT.", fk_input_method=".$methode.", date_commande='".$this->db->idate($date)."', "; @@ -1213,8 +1217,7 @@ class CommandeFournisseur extends CommonOrder $sql .= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::commande", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { $this->statut = self::STATUS_ORDERSENT; $this->methode_commande_id = $methode; $this->date_commande = $date; @@ -1222,7 +1225,9 @@ class CommandeFournisseur extends CommonOrder // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_SUBMIT', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } else { $error++; @@ -1230,8 +1235,7 @@ class CommandeFournisseur extends CommonOrder $this->errors[] = $this->db->lasterror(); } - if (!$error) - { + if (!$error) { $this->db->commit(); } else { $this->db->rollback(); @@ -1264,17 +1268,23 @@ class CommandeFournisseur extends CommonOrder // set tmp vars $date = ($this->date_commande ? $this->date_commande : $this->date); // in case of date is set - if (empty($date)) $date = $now; + if (empty($date)) { + $date = $now; + } $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date; // Clean parameters - if (empty($this->source)) $this->source = 0; + if (empty($this->source)) { + $this->source = 0; + } // Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate) - if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $date); - else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - if (empty($this->fk_multicurrency)) - { + if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) { + list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $date); + } else { + $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + } + if (empty($this->fk_multicurrency)) { $this->multicurrency_code = $conf->currency; $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; @@ -1330,16 +1340,14 @@ class CommandeFournisseur extends CommonOrder $sql .= ")"; dol_syslog(get_class($this)."::create", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."commande_fournisseur"); if ($this->id) { $num = count($this->lines); // insert products details into database - for ($i = 0; $i < $num; $i++) - { + for ($i = 0; $i < $num; $i++) { $this->special_code = $this->lines[$i]->special_code; // TODO : remove this in 9.0 and add special_code param to addline() // This include test on qty if option SUPPLIER_ORDER_WITH_NOPRICEDEFINED is not set @@ -1364,8 +1372,7 @@ class CommandeFournisseur extends CommonOrder $this->lines[$i]->array_options, $this->lines[$i]->fk_unit ); - if ($result < 0) - { + if ($result < 0) { dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); // do not use dol_print_error here as it may be a functionnal error $this->db->rollback(); return -1; @@ -1376,30 +1383,22 @@ class CommandeFournisseur extends CommonOrder $sql .= " SET ref='(PROV".$this->id.")'"; $sql .= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::create", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { // Add link with price request and supplier order - if ($this->id) - { + if ($this->id) { $this->ref = "(PROV".$this->id.")"; - if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects - { + if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds } // Add object linked - if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) - { - foreach ($this->linked_objects as $origin => $tmp_origin_id) - { - if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) - { - foreach ($tmp_origin_id as $origin_id) - { + if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) { + foreach ($this->linked_objects as $origin => $tmp_origin_id) { + if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + foreach ($tmp_origin_id as $origin_id) { $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { + if (!$ret) { dol_print_error($this->db); $error++; } @@ -1408,8 +1407,7 @@ class CommandeFournisseur extends CommonOrder { $origin_id = $tmp_origin_id; $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { + if (!$ret) { dol_print_error($this->db); $error++; } @@ -1418,18 +1416,17 @@ class CommandeFournisseur extends CommonOrder } } - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_CREATE', $user); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -1; } @@ -1467,19 +1464,18 @@ class CommandeFournisseur extends CommonOrder $this->db->begin(); // get extrafields so they will be clone - foreach ($this->lines as $line) + foreach ($this->lines as $line) { $line->fetch_optionals(); + } // Load source object $objFrom = clone $this; // Change socid if needed - if (!empty($socid) && $socid != $this->socid) - { + if (!empty($socid) && $socid != $this->socid) { $objsoc = new Societe($this->db); - if ($objsoc->fetch($socid) > 0) - { + if ($objsoc->fetch($socid) > 0) { $this->socid = $objsoc->id; $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); @@ -1507,25 +1503,26 @@ class CommandeFournisseur extends CommonOrder // Create clone $this->context['createfromclone'] = 'createfromclone'; $result = $this->create($user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } - if (!$error) - { + if (!$error) { // Hook of thirdparty module - if (is_object($hookmanager)) - { + if (is_object($hookmanager)) { $parameters = array('objFrom'=>$objFrom); $action = ''; $reshook = $hookmanager->executeHooks('createFrom', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks - if ($reshook < 0) $error++; + if ($reshook < 0) { + $error++; + } } } unset($this->context['createfromclone']); // End - if (!$error) - { + if (!$error) { $this->db->commit(); return $this->id; } else { @@ -1568,17 +1565,28 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $fk_prod_fourn_price, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, $info_bits, $notrigger, $date_start, $date_end, $fk_unit, $pu_ht_devise, $origin, $origin_id"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; - if ($this->statut == self::STATUS_DRAFT) - { + if ($this->statut == self::STATUS_DRAFT) { include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; // Clean parameters - if (empty($qty)) $qty = 0; - if (!$info_bits) $info_bits = 0; - if (empty($txtva)) $txtva = 0; - if (empty($txlocaltax1)) $txlocaltax1 = 0; - if (empty($txlocaltax2)) $txlocaltax2 = 0; - if (empty($remise_percent)) $remise_percent = 0; + if (empty($qty)) { + $qty = 0; + } + if (!$info_bits) { + $info_bits = 0; + } + if (empty($txtva)) { + $txtva = 0; + } + if (empty($txlocaltax1)) { + $txlocaltax1 = 0; + } + if (empty($txlocaltax2)) { + $txlocaltax2 = 0; + } + if (empty($remise_percent)) { + $remise_percent = 0; + } $remise_percent = price2num($remise_percent); $qty = price2num($qty); @@ -1590,8 +1598,7 @@ class CommandeFournisseur extends CommonOrder } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); - if ($price_base_type == 'HT') - { + if ($price_base_type == 'HT') { $pu = $pu_ht; } else { $pu = $pu_ttc; @@ -1599,12 +1606,13 @@ class CommandeFournisseur extends CommonOrder $desc = trim($desc); // Check parameters - if ($qty < 0 && !$fk_product) - { + if ($qty < 0 && !$fk_product) { $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Product")); return -1; } - if ($type < 0) return -1; + if ($type < 0) { + return -1; + } if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error = $langs->trans('ErrorStartDateGreaterEnd'); @@ -1632,15 +1640,15 @@ class CommandeFournisseur extends CommonOrder // If supplier order created from customer order, we take best supplier price // If $pu (defined previously from pu_ht or pu_ttc) is not defined at all, we also take the best supplier price - if ($result > 0 && ($origin == 'commande' || $pu === '')) - { + if ($result > 0 && ($origin == 'commande' || $pu === '')) { $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice $ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice // is remise percent not keyed but present for the product we add it - if ($remise_percent == 0 && $prod->remise_percent != 0) $remise_percent = $prod->remise_percent; + if ($remise_percent == 0 && $prod->remise_percent != 0) { + $remise_percent = $prod->remise_percent; + } } - if ($result == 0) // If result == 0, we failed to found the supplier reference price - { + if ($result == 0) { // If result == 0, we failed to found the supplier reference price $langs->load("errors"); $this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier"); $this->db->rollback(); @@ -1649,16 +1657,14 @@ class CommandeFournisseur extends CommonOrder //$ref = $prod->ref_fourn; // We do not overwrite ref supplier price return -1; } - if ($result == -1) - { + if ($result == -1) { $langs->load("errors"); $this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier"); $this->db->rollback(); dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG); return -1; } - if ($result < -1) - { + if ($result < -1) { $this->error = $prod->error; $this->db->rollback(); dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR); @@ -1695,8 +1701,7 @@ class CommandeFournisseur extends CommonOrder // Clean vat code $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $txtva, $reg)) - { + if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } @@ -1783,15 +1788,15 @@ class CommandeFournisseur extends CommonOrder } $result = $this->line->insert($notrigger); - if ($result > 0) - { + if ($result > 0) { // Reorder if child line - if (!empty($fk_parent_line)) $this->line_order(true, 'DESC'); + if (!empty($fk_parent_line)) { + $this->line_order(true, 'DESC'); + } // Mise a jour informations denormalisees au niveau de la commande meme $result = $this->update_price(1, 'auto', 0, $this->thirdparty); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. - if ($result > 0) - { + if ($result > 0) { $this->db->commit(); return $this->line->id; } else { @@ -1833,24 +1838,23 @@ class CommandeFournisseur extends CommonOrder require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; // Check parameters (if test are wrong here, there is bug into caller) - if ($entrepot <= 0) - { + if ($entrepot <= 0) { $this->error = 'ErrorBadValueForParameterWarehouse'; return -1; } - if ($qty == 0) - { + if ($qty == 0) { $this->error = 'ErrorBadValueForParameterQty'; return -1; } $dispatchstatus = 1; - if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 or 2 if this option is on + if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) { + $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 or 2 if this option is on + } $now = dol_now(); - if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) - { + if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) { $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch"; @@ -1861,15 +1865,12 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::dispatchProduct", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if (!$notrigger) - { + if ($resql) { + if (!$notrigger) { global $conf, $langs, $user; // Call trigger $result = $this->call_trigger('LINEORDER_SUPPLIER_DISPATCH', $user); - if ($result < 0) - { + if ($result < 0) { $error++; } // End call triggers @@ -1880,16 +1881,13 @@ class CommandeFournisseur extends CommonOrder } // If module stock is enabled and the stock increase is done on purchase order dispatching - if (!$error && $entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) - { + if (!$error && $entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) { $mouv = new MouvementStock($this->db); - if ($product > 0) - { + if ($product > 0) { // $price should take into account discount (except if option STOCK_EXCLUDE_DISCOUNT_FOR_PMP is on) $mouv->origin = &$this; $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch); - if ($result < 0) - { + if ($result < 0) { $this->error = $mouv->error; $this->errors = $mouv->errors; dol_syslog(get_class($this)."::dispatchProduct ".$this->error." ".join(',', $this->errors), LOG_ERR); @@ -1898,8 +1896,7 @@ class CommandeFournisseur extends CommonOrder } } - if ($error == 0) - { + if ($error == 0) { $this->db->commit(); return 1; } else { @@ -1921,17 +1918,14 @@ class CommandeFournisseur extends CommonOrder */ public function deleteline($idline, $notrigger = 0) { - if ($this->statut == 0) - { + if ($this->statut == 0) { $line = new CommandeFournisseurLigne($this->db); - if ($line->fetch($idline) <= 0) - { + if ($line->fetch($idline) <= 0) { return 0; } - if ($line->delete($notrigger) > 0) - { + if ($line->delete($notrigger) > 0) { $this->update_price(); return 1; } else { @@ -1960,12 +1954,10 @@ class CommandeFournisseur extends CommonOrder $this->db->begin(); - if (empty($notrigger)) - { + if (empty($notrigger)) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_DELETE', $user); - if ($result < 0) - { + if ($result < 0) { $this->errors[] = 'ErrorWhenRunningTrigger'; dol_syslog(get_class($this)."::delete ".$this->error, LOG_ERR); $this->db->rollback(); @@ -1978,8 +1970,7 @@ class CommandeFournisseur extends CommonOrder $ef = $main."_extrafields"; $sql = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".$this->id.")"; dol_syslog(get_class($this)."::delete extrafields lines", LOG_DEBUG); - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); $error++; @@ -1987,8 +1978,7 @@ class CommandeFournisseur extends CommonOrder $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE fk_commande =".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); $error++; @@ -1996,10 +1986,8 @@ class CommandeFournisseur extends CommonOrder $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur WHERE rowid =".$this->id; dol_syslog(get_class($this)."::delete", LOG_DEBUG); - if ($resql = $this->db->query($sql)) - { - if ($this->db->affected_rows($resql) < 1) - { + if ($resql = $this->db->query($sql)) { + if ($this->db->affected_rows($resql) < 1) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); $error++; @@ -2011,11 +1999,9 @@ class CommandeFournisseur extends CommonOrder } // Remove extrafields - if (!$error) - { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $this->error = 'FailToDeleteExtraFields'; $this->errors[] = 'FailToDeleteExtraFields'; $error++; @@ -2031,31 +2017,25 @@ class CommandeFournisseur extends CommonOrder $error++; } - if (!$error) - { + if (!$error) { // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive $this->deleteEcmFiles(); // We remove directory $ref = dol_sanitizeFileName($this->ref); - if ($conf->fournisseur->commande->dir_output) - { + if ($conf->fournisseur->commande->dir_output) { $dir = $conf->fournisseur->commande->dir_output."/".$ref; $file = $dir."/".$ref.".pdf"; - if (file_exists($file)) - { - if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers - { + if (file_exists($file)) { + if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers $this->error = 'ErrorFailToDeleteFile'; $this->errors[] = 'ErrorFailToDeleteFile'; $error++; } } - if (file_exists($dir)) - { + if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); - if (!$res) - { + if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $this->errors[] = 'ErrorFailToDeleteDir'; $error++; @@ -2064,8 +2044,7 @@ class CommandeFournisseur extends CommonOrder } } - if (!$error) - { + if (!$error) { dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG); $this->db->commit(); return 1; @@ -2090,13 +2069,11 @@ class CommandeFournisseur extends CommonOrder $sql .= " WHERE active = 1"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $i = 0; $num = $this->db->num_rows($resql); $this->methodes_commande = array(); - while ($i < $num) - { + while ($i < $num) { $row = $this->db->fetch_row($resql); $this->methodes_commande[$row[0]] = $row[1]; @@ -2130,20 +2107,19 @@ class CommandeFournisseur extends CommonOrder $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid"; $sql .= " WHERE cfd.fk_commande = ".$this->id; $sql .= " AND cfd.fk_product = p.rowid"; - if ($status >= 0) $sql .= " AND cfd.status = ".$status; + if ($status >= 0) { + $sql .= " AND cfd.status = ".$status; + } $sql .= " ORDER BY cfd.rowid ASC"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $this->db->fetch_object($resql); - if ($objp) - { + if ($objp) { $ret[] = array( 'id' => $objp->dispatchedlineid, 'productid' => $objp->fk_product, @@ -2154,7 +2130,9 @@ class CommandeFournisseur extends CommonOrder $i++; } - } else dol_print_error($this->db, 'Failed to execute request to get dispatched lines'); + } else { + dol_print_error($this->db, 'Failed to execute request to get dispatched lines'); + } return $ret; } @@ -2180,39 +2158,37 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::Livraison"); - if ($user->rights->fournisseur->commande->receptionner) - { + if ($user->rights->fournisseur->commande->receptionner) { // Define the new status - if ($type == 'par') $statut = self::STATUS_RECEIVED_PARTIALLY; - elseif ($type == 'tot') $statut = self::STATUS_RECEIVED_COMPLETELY; - elseif ($type == 'nev') $statut = self::STATUS_CANCELED_AFTER_ORDER; - elseif ($type == 'can') $statut = self::STATUS_CANCELED_AFTER_ORDER; - else { + if ($type == 'par') { + $statut = self::STATUS_RECEIVED_PARTIALLY; + } elseif ($type == 'tot') { + $statut = self::STATUS_RECEIVED_COMPLETELY; + } elseif ($type == 'nev') { + $statut = self::STATUS_CANCELED_AFTER_ORDER; + } elseif ($type == 'can') { + $statut = self::STATUS_CANCELED_AFTER_ORDER; + } else { $error++; dol_syslog(get_class($this)."::Livraison Error -2", LOG_ERR); return -2; } // Some checks to accept the record - if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) - { + if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) { // If option SUPPLIER_ORDER_USE_DISPATCH_STATUS is on, we check all reception are approved to allow status "total/done" - if (!$error && ($type == 'tot')) - { + if (!$error && ($type == 'tot')) { $dispatchedlinearray = $this->getDispachedLines(0); - if (count($dispatchedlinearray) > 0) - { + if (count($dispatchedlinearray) > 0) { $result = -1; $error++; $this->errors[] = 'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove'; dol_syslog('ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG); } } - if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type == 'tot')) // Accept to move to reception done, only if status of all line are ok (refuse denied) - { + if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type == 'tot')) { // Accept to move to reception done, only if status of all line are ok (refuse denied) $dispatcheddenied = $this->getDispachedLines(2); - if (count($dispatchedlinearray) > 0) - { + if (count($dispatchedlinearray) > 0) { $result = -1; $error++; $this->errors[] = 'ErrorCantSetReceptionToTotalDoneWithReceptionDenied'; @@ -2223,8 +2199,7 @@ class CommandeFournisseur extends CommonOrder // TODO LDR01 Add a control test to accept only if ALL predefined products are received (same qty). - if (empty($error)) - { + if (empty($error)) { $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; @@ -2234,8 +2209,7 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::Livraison", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $result = 1; $old_statut = $this->statut; $this->statut = $statut; @@ -2243,11 +2217,12 @@ class CommandeFournisseur extends CommonOrder // Call trigger $result_trigger = $this->call_trigger('ORDER_SUPPLIER_RECEIVE', $user); - if ($result_trigger < 0) $error++; + if ($result_trigger < 0) { + $error++; + } // End call triggers - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); } else { $this->statut = $old_statut; @@ -2296,8 +2271,7 @@ class CommandeFournisseur extends CommonOrder */ public function setDeliveryDate($user, $delivery_date, $notrigger = 0) { - if ($user->rights->fournisseur->commande->creer) - { + if ($user->rights->fournisseur->commande->creer) { $error = 0; $this->db->begin(); @@ -2308,34 +2282,31 @@ class CommandeFournisseur extends CommonOrder dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->errors[] = $this->db->error(); $error++; } - if (!$error) - { + if (!$error) { $this->oldcopy = clone $this; $this->date_livraison = $delivery_date; $this->delivery_date = $delivery_date; } - if (!$notrigger && empty($error)) - { + if (!$notrigger && empty($error)) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_MODIFY', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { - foreach ($this->errors as $errmsg) - { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -2359,8 +2330,7 @@ class CommandeFournisseur extends CommonOrder public function set_id_projet($user, $id_projet, $notrigger = 0) { // phpcs:enable - if ($user->rights->fournisseur->commande->creer) - { + if ($user->rights->fournisseur->commande->creer) { $error = 0; $this->db->begin(); @@ -2371,34 +2341,31 @@ class CommandeFournisseur extends CommonOrder dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->errors[] = $this->db->error(); $error++; } - if (!$error) - { + if (!$error) { $this->oldcopy = clone $this; $this->fk_projet = $id_projet; $this->fk_project = $id_projet; } - if (!$notrigger && empty($error)) - { + if (!$notrigger && empty($error)) { // Call trigger $result = $this->call_trigger('ORDER_SUPPLIER_MODIFY', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { - foreach ($this->errors as $errmsg) - { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -2428,13 +2395,11 @@ class CommandeFournisseur extends CommonOrder $this->lines = array(); $num = count($comclient->lines); - for ($i = 0; $i < $num; $i++) - { + for ($i = 0; $i < $num; $i++) { $prod = new Product($this->db); $label = ''; $ref = ''; - if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) - { + if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) { $label = $prod->label; $ref = $prod->ref; } @@ -2445,8 +2410,7 @@ class CommandeFournisseur extends CommonOrder $sql .= ",".$comclient->lines[$i]->fk_product.", ".price2num($comclient->lines[$i]->price); $sql .= ", ".$comclient->lines[$i]->qty.", ".$comclient->lines[$i]->tva_tx.", ".$comclient->lines[$i]->localtax1_tx.", ".$comclient->lines[$i]->localtax2_tx.", ".$comclient->lines[$i]->remise_percent; $sql .= ", '".price2num($comclient->lines[$i]->subprice)."','0', '".$this->db->escape($ref)."');"; - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { $this->update_price(); } } @@ -2474,8 +2438,7 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::setStatus", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { // Trigger names for each status $triggerName = array(); $triggerName[0] = 'DRAFT'; @@ -2490,7 +2453,9 @@ class CommandeFournisseur extends CommonOrder // Call trigger $result = $this->call_trigger("ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } else { $error++; @@ -2498,8 +2463,7 @@ class CommandeFournisseur extends CommonOrder dol_syslog(get_class($this)."::setStatus ".$this->error); } - if (!$error) - { + if (!$error) { $this->statut = $status; $this->db->commit(); return 1; @@ -2540,30 +2504,47 @@ class CommandeFournisseur extends CommonOrder $error = 0; - if ($this->brouillon) - { + if ($this->brouillon) { // Clean parameters - if (empty($qty)) $qty = 0; - if (empty($info_bits)) $info_bits = 0; - if (empty($txtva)) $txtva = 0; - if (empty($txlocaltax1)) $txlocaltax1 = 0; - if (empty($txlocaltax2)) $txlocaltax2 = 0; - if (empty($remise)) $remise = 0; - if (empty($remise_percent)) $remise_percent = 0; + if (empty($qty)) { + $qty = 0; + } + if (empty($info_bits)) { + $info_bits = 0; + } + if (empty($txtva)) { + $txtva = 0; + } + if (empty($txlocaltax1)) { + $txlocaltax1 = 0; + } + if (empty($txlocaltax2)) { + $txlocaltax2 = 0; + } + if (empty($remise)) { + $remise = 0; + } + if (empty($remise_percent)) { + $remise_percent = 0; + } $remise_percent = price2num($remise_percent); $qty = price2num($qty); - if (!$qty) $qty = 1; + if (!$qty) { + $qty = 1; + } $pu = price2num($pu); $pu_ht_devise = price2num($pu_ht_devise); - if (!preg_match('/\((.*)\)/', $txtva)) { - $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' - } + if (!preg_match('/\((.*)\)/', $txtva)) { + $txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5' + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); // Check parameters - if ($type < 0) return -1; + if ($type < 0) { + return -1; + } if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); $this->error = $langs->trans('ErrorStartDateGreaterEnd'); @@ -2582,8 +2563,7 @@ class CommandeFournisseur extends CommonOrder // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $txtva, $reg)) - { + if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } @@ -2621,14 +2601,11 @@ class CommandeFournisseur extends CommonOrder $this->line->desc = $desc; // redefine quantity according to packaging - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) - { - if ($qty < $this->line->packaging) - { + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { + if ($qty < $this->line->packaging) { $qty = $this->line->packaging; } else { - if (($qty % $this->line->packaging) > 0) - { + if (($qty % $this->line->packaging) > 0) { $coeff = intval($qty / $this->line->packaging) + 1; $qty = $this->line->packaging * $coeff; setEventMessage($langs->trans('QtyRecalculatedWithPackaging'), 'mesgs'); @@ -2686,8 +2663,7 @@ class CommandeFournisseur extends CommonOrder // Mise a jour info denormalisees au niveau facture - if ($result >= 0) - { + if ($result >= 0) { $this->update_price('', 'auto'); $this->db->commit(); return $result; @@ -2730,8 +2706,7 @@ class CommandeFournisseur extends CommonOrder $sql .= $this->db->order("rowid", "ASC"); $sql .= $this->db->plimit(1); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); $prodid = $obj->rowid; } @@ -2758,8 +2733,7 @@ class CommandeFournisseur extends CommonOrder // Lines $nbp = 5; $xnbp = 0; - while ($xnbp < $nbp) - { + while ($xnbp < $nbp) { $line = new CommandeFournisseurLigne($this->db); $line->desc = $langs->trans("Description")." ".$xnbp; $line->qty = 1; @@ -2768,8 +2742,7 @@ class CommandeFournisseur extends CommonOrder $line->tva_tx = 19.6; $line->localtax1_tx = 0; $line->localtax2_tx = 0; - if ($xnbp == 2) - { + if ($xnbp == 2) { $line->total_ht = 50; $line->total_ttc = 59.8; $line->total_tva = 9.8; @@ -2806,17 +2779,25 @@ class CommandeFournisseur extends CommonOrder $sql .= ' WHERE c.rowid = '.$id; $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - if ($obj->fk_user_author) $this->user_creation_id = $obj->fk_user_author; - if ($obj->fk_user_valid) $this->user_validation_id = $obj->fk_user_valid; - if ($obj->fk_user_modif) $this->user_modification_id = $obj->fk_user_modif; - if ($obj->fk_user_approve) $this->user_approve_id = $obj->fk_user_approve; - if ($obj->fk_user_approve2) $this->user_approve_id2 = $obj->fk_user_approve2; + if ($obj->fk_user_author) { + $this->user_creation_id = $obj->fk_user_author; + } + if ($obj->fk_user_valid) { + $this->user_validation_id = $obj->fk_user_valid; + } + if ($obj->fk_user_modif) { + $this->user_modification_id = $obj->fk_user_modif; + } + if ($obj->fk_user_approve) { + $this->user_approve_id = $obj->fk_user_approve; + } + if ($obj->fk_user_approve2) { + $this->user_approve_id2 = $obj->fk_user_approve2; + } $this->date_creation = $this->db->idate($obj->datec); $this->date_modification = $this->db->idate($obj->datem); @@ -2847,8 +2828,7 @@ class CommandeFournisseur extends CommonOrder $sql = "SELECT count(co.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as co"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON co.fk_soc = s.rowid"; - if (!$user->rights->societe->client->voir && !$user->socid) - { + if (!$user->rights->societe->client->voir && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; $sql .= " WHERE sc.fk_user = ".$user->id; $clause = "AND"; @@ -2856,10 +2836,8 @@ class CommandeFournisseur extends CommonOrder $sql .= " ".$clause." co.entity = ".$conf->entity; $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->nb["supplier_orders"] = $obj->nb; } $this->db->free($resql); @@ -2888,8 +2866,7 @@ class CommandeFournisseur extends CommonOrder $sql = "SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date"; $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; - if (!$user->rights->societe->client->voir && !$user->socid) - { + if (!$user->rights->societe->client->voir && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON c.fk_soc = sc.fk_soc"; $sql .= " WHERE sc.fk_user = ".$user->id; $clause = " AND"; @@ -2900,11 +2877,12 @@ class CommandeFournisseur extends CommonOrder } else { $sql .= " AND c.fk_statut IN (".self::STATUS_VALIDATED.", ".self::STATUS_ACCEPTED.")"; } - if ($user->socid) $sql .= " AND c.fk_soc = ".$user->socid; + if ($user->socid) { + $sql .= " AND c.fk_soc = ".$user->socid; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $commandestatic = new CommandeFournisseur($this->db); $response = new WorkboardResponse(); @@ -2920,8 +2898,7 @@ class CommandeFournisseur extends CommonOrder $response->url = DOL_URL_ROOT.'/fourn/commande/list.php?statut=3,4&mainmenu=commercial&leftmenu=orders_suppliers'; } - while ($obj = $this->db->fetch_object($resql)) - { + while ($obj = $this->db->fetch_object($resql)) { $response->nbtodo++; $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date); @@ -2950,27 +2927,25 @@ class CommandeFournisseur extends CommonOrder { global $db, $langs; - if ($this->methode_commande_id > 0) - { + if ($this->methode_commande_id > 0) { $sql = "SELECT rowid, code, libelle as label"; $sql .= " FROM ".MAIN_DB_PREFIX.'c_input_method'; $sql .= " WHERE active=1 AND rowid = ".$this->db->escape($this->methode_commande_id); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { + if ($resql) { + if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); $string = $langs->trans($obj->code); - if ($string == $obj->code) - { + if ($string == $obj->code) { $string = $obj->label != '-' ? $obj->label : ''; } return $string; } - } else dol_print_error($this->db); + } else { + dol_print_error($this->db); + } } return ''; @@ -3017,26 +2992,30 @@ class CommandeFournisseur extends CommonOrder */ public function getMaxDeliveryTimeDay($langs) { - if (empty($this->lines)) return ''; + if (empty($this->lines)) { + return ''; + } $obj = new ProductFournisseur($this->db); $nb = 0; - foreach ($this->lines as $line) - { - if ($line->fk_product > 0) - { + foreach ($this->lines as $line) { + if ($line->fk_product > 0) { $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty); - if ($idp) - { + if ($idp) { $obj->fetch($idp); - if ($obj->delivery_time_days > $nb) $nb = $obj->delivery_time_days; + if ($obj->delivery_time_days > $nb) { + $nb = $obj->delivery_time_days; + } } } } - if ($nb === 0) return ''; - else return $nb.' '.$langs->trans('Days'); + if ($nb === 0) { + return ''; + } else { + return $nb.' '.$langs->trans('Days'); + } } /** @@ -3079,7 +3058,9 @@ class CommandeFournisseur extends CommonOrder { global $conf; - if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison; // For backward compatibility + if (empty($this->delivery_date) && !empty($this->date_livraison)) { + $this->delivery_date = $this->date_livraison; // For backward compatibility + } if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) { $now = dol_now(); @@ -3110,7 +3091,9 @@ class CommandeFournisseur extends CommonOrder { global $conf, $langs; - if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison; // For backward compatibility + if (empty($this->delivery_date) && !empty($this->date_livraison)) { + $this->delivery_date = $this->date_livraison; // For backward compatibility + } $text = ''; @@ -3143,8 +3126,7 @@ class CommandeFournisseur extends CommonOrder { global $conf, $langs; - if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) - { + if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled)) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php'; $qtydelivered = array(); @@ -3171,7 +3153,9 @@ class CommandeFournisseur extends CommonOrder } foreach ($this->lines as $line) { // Exclude lines not qualified for shipment, similar code is found into interface_20_modWrokflow for customers - if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0) continue; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0) { + continue; + } $qtywished[$line->fk_product] += $line->qty; } @@ -3181,16 +3165,14 @@ class CommandeFournisseur extends CommonOrder $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished)); // To check we also have same number of keys /*var_dump(array_keys($qtydelivered)); - var_dump(array_keys($qtywished)); - var_dump($diff_array); - var_dump($keysinwishednotindelivered); - var_dump($keysindeliverednotinwished); - exit;*/ + var_dump(array_keys($qtywished)); + var_dump($diff_array); + var_dump($keysinwishednotindelivered); + var_dump($keysindeliverednotinwished); + exit;*/ - if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) //No diff => mean everythings is received - { - if ($closeopenorder) - { + if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) { //No diff => mean everythings is received + if ($closeopenorder) { //$ret=$this->setStatus($user,5); $ret = $this->Livraison($user, $date_liv, 'tot', $comment); // GETPOST("type") is 'tot', 'par', 'nev', 'can' if ($ret < 0) { @@ -3211,16 +3193,13 @@ class CommandeFournisseur extends CommonOrder $close = 0; - if (count($diff_array) > 0) - { + if (count($diff_array) > 0) { //there are some difference between the two arrays //scan the array of results - foreach ($diff_array as $key => $value) - { + foreach ($diff_array as $key => $value) { //if the quantity delivered is greater or equal to wish quantity - if ($qtydelivered[$key] >= $qtywished[$key]) - { + if ($qtydelivered[$key] >= $qtywished[$key]) { $close++; } } @@ -3280,25 +3259,31 @@ class CommandeFournisseur extends CommonOrder $sql = 'SELECT cd.rowid, cd.fk_product,'; $sql .= ' sum(cfd.qty) as qty'; $sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch as cfd,'; - if ($filtre_statut >= 0) $sql .= ' '.MAIN_DB_PREFIX.'reception as e,'; + if ($filtre_statut >= 0) { + $sql .= ' '.MAIN_DB_PREFIX.'reception as e,'; + } $sql .= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd'; $sql .= ' WHERE'; - if ($filtre_statut >= 0) $sql .= ' cfd.fk_reception = e.rowid AND'; + if ($filtre_statut >= 0) { + $sql .= ' cfd.fk_reception = e.rowid AND'; + } $sql .= ' cfd.fk_commandefourndet = cd.rowid'; $sql .= ' AND cd.fk_commande ='.$this->id; - if ($this->fk_product > 0) $sql .= ' AND cd.fk_product = '.$this->fk_product; - if ($filtre_statut >= 0) $sql .= ' AND e.fk_statut >= '.$filtre_statut; + if ($this->fk_product > 0) { + $sql .= ' AND cd.fk_product = '.$this->fk_product; + } + if ($filtre_statut >= 0) { + $sql .= ' AND e.fk_statut >= '.$filtre_statut; + } $sql .= ' GROUP BY cd.rowid, cd.fk_product'; dol_syslog(get_class($this)."::loadReceptions", LOG_DEBUG); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($result); empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty; $i++; @@ -3399,20 +3384,20 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,'; $sql .= ' cd.date_start, cd.date_end, cd.fk_unit,'; $sql .= ' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc'; - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $sql .= ", pfp.rowid as fk_pfp, pfp.packaging"; + } $sql .= ' FROM '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON cd.fk_product = p.rowid'; - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON cd.fk_product = pfp.fk_product and cd.ref = pfp.ref_fourn"; + } $sql .= ' WHERE cd.rowid = '.$rowid; $result = $this->db->query($sql); - if ($result) - { + if ($result) { $objp = $this->db->fetch_object($result); - if (!empty($objp)) - { + if (!empty($objp)) { $this->rowid = $objp->rowid; $this->id = $objp->rowid; $this->fk_commande = $objp->fk_commande; @@ -3443,8 +3428,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $this->product_ref = $objp->product_ref; $this->product_label = $objp->product_label; $this->product_desc = $objp->product_desc; - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) - { + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $this->packaging = $objp->packaging; $this->fk_fournprice = $objp->fk_pfp; } @@ -3488,32 +3472,63 @@ class CommandeFournisseurLigne extends CommonOrderLine dol_syslog(get_class($this)."::insert rang=".$this->rang); // Clean parameters - if (empty($this->tva_tx)) $this->tva_tx = 0; - if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; - if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; - if (empty($this->localtax1_type)) $this->localtax1_type = '0'; - if (empty($this->localtax2_type)) $this->localtax2_type = '0'; - if (empty($this->total_localtax1)) $this->total_localtax1 = 0; - if (empty($this->total_localtax2)) $this->total_localtax2 = 0; - if (empty($this->rang)) $this->rang = 0; - if (empty($this->remise)) $this->remise = 0; - if (empty($this->remise_percent)) $this->remise_percent = 0; - if (empty($this->info_bits)) $this->info_bits = 0; - if (empty($this->special_code)) $this->special_code = 0; - if (empty($this->fk_parent_line)) $this->fk_parent_line = 0; - if (empty($this->pa_ht)) $this->pa_ht = 0; + if (empty($this->tva_tx)) { + $this->tva_tx = 0; + } + if (empty($this->localtax1_tx)) { + $this->localtax1_tx = 0; + } + if (empty($this->localtax2_tx)) { + $this->localtax2_tx = 0; + } + if (empty($this->localtax1_type)) { + $this->localtax1_type = '0'; + } + if (empty($this->localtax2_type)) { + $this->localtax2_type = '0'; + } + if (empty($this->total_localtax1)) { + $this->total_localtax1 = 0; + } + if (empty($this->total_localtax2)) { + $this->total_localtax2 = 0; + } + if (empty($this->rang)) { + $this->rang = 0; + } + if (empty($this->remise)) { + $this->remise = 0; + } + if (empty($this->remise_percent)) { + $this->remise_percent = 0; + } + if (empty($this->info_bits)) { + $this->info_bits = 0; + } + if (empty($this->special_code)) { + $this->special_code = 0; + } + if (empty($this->fk_parent_line)) { + $this->fk_parent_line = 0; + } + if (empty($this->pa_ht)) { + $this->pa_ht = 0; + } // Multicurrency - if (!empty($this->multicurrency_code)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code); - if (empty($this->fk_multicurrency)) - { + if (!empty($this->multicurrency_code)) { + list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code); + } + if (empty($this->fk_multicurrency)) { $this->multicurrency_code = $conf->currency; $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } // Check parameters - if ($this->product_type < 0) return -1; + if ($this->product_type < 0) { + return -1; + } $this->db->begin(); @@ -3528,7 +3543,11 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql .= " VALUES (".$this->fk_commande.", '".$this->db->escape($this->label)."','".$this->db->escape($this->desc)."',"; $sql .= " ".($this->date_start ? "'".$this->db->idate($this->date_start)."'" : "null").","; $sql .= " ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null").","; - if ($this->fk_product) { $sql .= $this->fk_product.","; } else { $sql .= "null,"; } + if ($this->fk_product) { + $sql .= $this->fk_product.","; + } else { + $sql .= "null,"; + } $sql .= "'".$this->db->escape($this->product_type)."',"; $sql .= "'".$this->db->escape($this->special_code)."',"; $sql .= "'".$this->db->escape($this->rang)."',"; @@ -3556,25 +3575,23 @@ class CommandeFournisseurLigne extends CommonOrderLine dol_syslog(get_class($this)."::insert", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); $this->rowid = $this->id; - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('LINEORDER_SUPPLIER_CREATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } @@ -3583,8 +3600,7 @@ class CommandeFournisseurLigne extends CommonOrderLine return 1; } - foreach ($this->errors as $errmsg) - { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); $this->errors[] = ($this->errors ? ', '.$errmsg : $errmsg); } @@ -3647,32 +3663,26 @@ class CommandeFournisseurLigne extends CommonOrderLine dol_syslog(get_class($this)."::updateline", LOG_DEBUG); $result = $this->db->query($sql); - if ($result > 0) - { - if (!$error) - { + if ($result > 0) { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { global $user; // Call trigger $result = $this->call_trigger('LINEORDER_SUPPLIER_UPDATE', $user); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -1; } // End call triggers } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -3702,8 +3712,7 @@ class CommandeFournisseurLigne extends CommonOrderLine // extrafields $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -1; } @@ -3712,24 +3721,22 @@ class CommandeFournisseurLigne extends CommonOrderLine dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if (!$notrigger) - { + if ($resql) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('LINEORDER_SUPPLIER_DELETE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } - foreach ($this->errors as $errmsg) - { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index a7abed27369..c79a53297f2 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -140,16 +140,36 @@ class CommandeFournisseurDispatch extends CommonObject // Clean parameters - if (isset($this->fk_commande)) $this->fk_commande = trim($this->fk_commande); - if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product); - if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet = trim($this->fk_commandefourndet); - if (isset($this->qty)) $this->qty = trim($this->qty); - if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot); - if (isset($this->fk_user)) $this->fk_user = trim($this->fk_user); - if (isset($this->comment)) $this->comment = trim($this->comment); - if (isset($this->status)) $this->status = trim($this->status); - if (isset($this->batch)) $this->batch = trim($this->batch); - if (empty($this->datec)) $this->datec = dol_now(); + if (isset($this->fk_commande)) { + $this->fk_commande = trim($this->fk_commande); + } + if (isset($this->fk_product)) { + $this->fk_product = trim($this->fk_product); + } + if (isset($this->fk_commandefourndet)) { + $this->fk_commandefourndet = trim($this->fk_commandefourndet); + } + if (isset($this->qty)) { + $this->qty = trim($this->qty); + } + if (isset($this->fk_entrepot)) { + $this->fk_entrepot = trim($this->fk_entrepot); + } + if (isset($this->fk_user)) { + $this->fk_user = trim($this->fk_user); + } + if (isset($this->comment)) { + $this->comment = trim($this->comment); + } + if (isset($this->status)) { + $this->status = trim($this->status); + } + if (isset($this->batch)) { + $this->batch = trim($this->batch); + } + if (empty($this->datec)) { + $this->datec = dol_now(); + } // Check parameters @@ -190,16 +210,16 @@ class CommandeFournisseurDispatch extends CommonObject $this->db->begin(); - dol_syslog(__METHOD__, LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } - if (!$error) - { + if (!$error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); - if (!$notrigger) - { + if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. @@ -211,17 +231,16 @@ class CommandeFournisseurDispatch extends CommonObject } // Create extrafields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -264,15 +283,16 @@ class CommandeFournisseurDispatch extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; - if ($ref) $sql .= " WHERE t.ref = '".$ref."'"; - else $sql .= " WHERE t.rowid = ".$id; + if ($ref) { + $sql .= " WHERE t.ref = '".$ref."'"; + } else { + $sql .= " WHERE t.rowid = ".$id; + } dol_syslog(get_class($this)."::fetch"); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { + if ($resql) { + if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -318,15 +338,33 @@ class CommandeFournisseurDispatch extends CommonObject // Clean parameters - if (isset($this->fk_commande)) $this->fk_commande = trim($this->fk_commande); - if (isset($this->fk_product)) $this->fk_product = trim($this->fk_product); - if (isset($this->fk_commandefourndet)) $this->fk_commandefourndet = trim($this->fk_commandefourndet); - if (isset($this->qty)) $this->qty = trim($this->qty); - if (isset($this->fk_entrepot)) $this->fk_entrepot = trim($this->fk_entrepot); - if (isset($this->fk_user)) $this->fk_user = trim($this->fk_user); - if (isset($this->comment)) $this->comment = trim($this->comment); - if (isset($this->status)) $this->status = trim($this->status); - if (isset($this->batch)) $this->batch = trim($this->batch); + if (isset($this->fk_commande)) { + $this->fk_commande = trim($this->fk_commande); + } + if (isset($this->fk_product)) { + $this->fk_product = trim($this->fk_product); + } + if (isset($this->fk_commandefourndet)) { + $this->fk_commandefourndet = trim($this->fk_commandefourndet); + } + if (isset($this->qty)) { + $this->qty = trim($this->qty); + } + if (isset($this->fk_entrepot)) { + $this->fk_entrepot = trim($this->fk_entrepot); + } + if (isset($this->fk_user)) { + $this->fk_user = trim($this->fk_user); + } + if (isset($this->comment)) { + $this->comment = trim($this->comment); + } + if (isset($this->status)) { + $this->status = trim($this->status); + } + if (isset($this->batch)) { + $this->batch = trim($this->batch); + } @@ -357,34 +395,34 @@ class CommandeFournisseurDispatch extends CommonObject dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } - if (!$error) - { - if (!$error) - { - if (empty($this->id) && !empty($this->rowid))$this->id = $this->rowid; + if (!$error) { + if (!$error) { + if (empty($this->id) && !empty($this->rowid)) { + $this->id = $this->rowid; + } $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$notrigger) - { + if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you $result = $this->call_trigger('LINERECEPTION_UPDATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } //// End call triggers } } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -397,13 +435,13 @@ class CommandeFournisseurDispatch extends CommonObject } - /** - * Delete object in database - * - * @param User $user User that deletes - * @param int $notrigger 0=launch triggers after, 1=disable triggers - * @return int <0 if KO, >0 if OK - */ + /** + * Delete object in database + * + * @param User $user User that deletes + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ public function delete($user, $notrigger = 0) { global $conf, $langs; @@ -411,10 +449,8 @@ class CommandeFournisseurDispatch extends CommonObject $this->db->begin(); - if (!$error) - { - if (!$notrigger) - { + if (!$error) { + if (!$notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. @@ -428,28 +464,26 @@ class CommandeFournisseurDispatch extends CommonObject // Remove extrafields if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR); } } - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; $sql .= " WHERE rowid=".$this->id; dol_syslog(__METHOD__); $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } + if (!$resql) { + $error++; $this->errors[] = "Error ".$this->db->lasterror(); + } } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(__METHOD__." ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -491,21 +525,18 @@ class CommandeFournisseurDispatch extends CommonObject $result = $object->create($user); // Other options - if ($result < 0) - { + if ($result < 0) { $this->error = $object->error; $error++; } - if (!$error) - { + if (!$error) { } unset($object->context['createfromclone']); // End - if (!$error) - { + if (!$error) { $this->db->commit(); return $object->id; } else { @@ -541,30 +572,36 @@ class CommandeFournisseurDispatch extends CommonObject global $langs; $langs->load('orders'); - if ($mode == 0) - { + if ($mode == 0) { return $langs->trans($this->statuts[$status]); - } elseif ($mode == 1) - { + } elseif ($mode == 1) { return $langs->trans($this->statutshort[$status]); - } elseif ($mode == 2) - { + } elseif ($mode == 2) { return $langs->trans($this->statuts[$status]); - } elseif ($mode == 3) - { - if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut0'); - elseif ($status == 1) return img_picto($langs->trans($this->statuts[$status]), 'statut4'); - elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut8'); - } elseif ($mode == 4) - { - if ($status == 0) return img_picto($langs->trans($this->statuts[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]); - elseif ($status == 1) return img_picto($langs->trans($this->statuts[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]); - elseif ($status == 2) return img_picto($langs->trans($this->statuts[$status]), 'statut8').' '.$langs->trans($this->statuts[$status]); - } elseif ($mode == 5) - { - if ($status == 0) return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut0'); - elseif ($status == 1) return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut4'); - elseif ($status == 2) return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut8'); + } elseif ($mode == 3) { + if ($status == 0) { + return img_picto($langs->trans($this->statuts[$status]), 'statut0'); + } elseif ($status == 1) { + return img_picto($langs->trans($this->statuts[$status]), 'statut4'); + } elseif ($status == 2) { + return img_picto($langs->trans($this->statuts[$status]), 'statut8'); + } + } elseif ($mode == 4) { + if ($status == 0) { + return img_picto($langs->trans($this->statuts[$status]), 'statut0').' '.$langs->trans($this->statuts[$status]); + } elseif ($status == 1) { + return img_picto($langs->trans($this->statuts[$status]), 'statut4').' '.$langs->trans($this->statuts[$status]); + } elseif ($status == 2) { + return img_picto($langs->trans($this->statuts[$status]), 'statut8').' '.$langs->trans($this->statuts[$status]); + } + } elseif ($mode == 5) { + if ($status == 0) { + return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut0'); + } elseif ($status == 1) { + return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut4'); + } elseif ($status == 2) { + return ''.$langs->trans($this->statutshort[$status]).' '.img_picto($langs->trans($this->statuts[$status]), 'statut8'); + } } } @@ -610,7 +647,7 @@ class CommandeFournisseurDispatch extends CommonObject { dol_syslog(__METHOD__, LOG_DEBUG); - $sql = "SELECT"; + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.fk_commande,"; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 0157dbd0eec..2336b22a366 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -38,8 +38,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commoninvoice.class.php'; require_once DOL_DOCUMENT_ROOT.'/multicurrency/class/multicurrency.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; -if (!empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; +if (!empty($conf->accounting->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php'; +} +if (!empty($conf->accounting->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php'; +} /** * Class to manage suppliers invoices @@ -350,9 +354,15 @@ class FactureFournisseur extends CommonInvoice $now = dol_now(); // Clean parameters - if (isset($this->ref_supplier)) $this->ref_supplier = trim($this->ref_supplier); - if (empty($this->type)) $this->type = self::TYPE_STANDARD; - if (empty($this->date)) $this->date = $now; + if (isset($this->ref_supplier)) { + $this->ref_supplier = trim($this->ref_supplier); + } + if (empty($this->type)) { + $this->type = self::TYPE_STANDARD; + } + if (empty($this->date)) { + $this->date = $now; + } $socid = $this->socid; $ref_supplier = $this->ref_supplier; @@ -360,10 +370,12 @@ class FactureFournisseur extends CommonInvoice $remise = $this->remise; // Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate) - if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); - else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); - if (empty($this->fk_multicurrency)) - { + if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) { + list($this->fk_multicurrency, $this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $this->date); + } else { + $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); + } + if (empty($this->fk_multicurrency)) { $this->multicurrency_code = $conf->currency; $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; @@ -371,7 +383,9 @@ class FactureFournisseur extends CommonInvoice $this->db->begin(); - if (!$remise) $remise = 0; + if (!$remise) { + $remise = 0; + } $sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn ("; $sql .= "ref"; @@ -423,8 +437,7 @@ class FactureFournisseur extends CommonInvoice dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn'); // Update ref with new one @@ -433,25 +446,21 @@ class FactureFournisseur extends CommonInvoice dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) $error++; + if (!$resql) { + $error++; + } - if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects - { + if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) { // To use new linkedObjectsIds instead of old linked_objects $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds } // Add object linked - if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) - { - foreach ($this->linked_objects as $origin => $tmp_origin_id) - { - if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) - { - foreach ($tmp_origin_id as $origin_id) - { + if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) { + foreach ($this->linked_objects as $origin => $tmp_origin_id) { + if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + foreach ($tmp_origin_id as $origin_id) { $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { + if (!$ret) { dol_print_error($this->db); $error++; } @@ -460,8 +469,7 @@ class FactureFournisseur extends CommonInvoice { $origin_id = $tmp_origin_id; $ret = $this->add_object_linked($origin, $origin_id); - if (!$ret) - { + if (!$ret) { dol_print_error($this->db); $error++; } @@ -469,17 +477,14 @@ class FactureFournisseur extends CommonInvoice } } - if (count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode) - { + if (count($this->lines) && is_object($this->lines[0])) { // If this->lines is array of InvoiceLines (preferred mode) dol_syslog("There is ".count($this->lines)." lines that are invoice lines objects"); - foreach ($this->lines as $i => $val) - { + foreach ($this->lines as $i => $val) { $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn, special_code)'; $sql .= ' VALUES ('.$this->id.','.intval($this->lines[$i]->special_code).')'; $resql_insert = $this->db->query($sql); - if ($resql_insert) - { + if ($resql_insert) { $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); $this->updateline( @@ -511,20 +516,20 @@ class FactureFournisseur extends CommonInvoice } else // If this->lines is an array of invoice line arrays { dol_syslog("There is ".count($this->lines)." lines that are array lines"); - foreach ($this->lines as $i => $val) - { + foreach ($this->lines as $i => $val) { $line = $this->lines[$i]; // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array //if (! is_object($line)) $line=json_decode(json_encode($line), false); // convert recursively array into object. - if (!is_object($line)) $line = (object) $line; + if (!is_object($line)) { + $line = (object) $line; + } $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn, special_code)'; $sql .= ' VALUES ('.$this->id.','.intval($this->lines[$i]->special_code).')'; $resql_insert = $this->db->query($sql); - if ($resql_insert) - { + if ($resql_insert) { $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); $this->updateline( @@ -539,7 +544,7 @@ class FactureFournisseur extends CommonInvoice 'HT', (!empty($line->info_bits) ? $line->info_bits : ''), $line->product_type - ); + ); } else { $this->error = $this->db->lasterror(); $this->db->rollback(); @@ -550,28 +555,25 @@ class FactureFournisseur extends CommonInvoice // Update total price $result = $this->update_price(); - if ($result > 0) - { + if ($result > 0) { // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); // This also set $this->error or $this->errors if errors are found - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error) - { + if (!$error) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_CREATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->db->commit(); return $this->id; } else { @@ -584,8 +586,7 @@ class FactureFournisseur extends CommonInvoice return -3; } } else { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error = $langs->trans('ErrorRefAlreadyExists'); $this->db->rollback(); return -1; @@ -655,15 +656,17 @@ class FactureFournisseur extends CommonInvoice $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_payment_term as cr ON t.fk_cond_reglement = cr.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as p ON t.fk_mode_reglement = p.id"; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON t.fk_incoterms = i.rowid'; - if ($id) $sql .= " WHERE t.rowid=".$id; - if ($ref) $sql .= " WHERE t.ref='".$this->db->escape($ref)."' AND t.entity IN (".getEntity('supplier_invoice').")"; + if ($id) { + $sql .= " WHERE t.rowid=".$id; + } + if ($ref) { + $sql .= " WHERE t.ref='".$this->db->escape($ref)."' AND t.entity IN (".getEntity('supplier_invoice').")"; + } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - if ($this->db->num_rows($resql)) - { + if ($resql) { + if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -737,11 +740,12 @@ class FactureFournisseur extends CommonInvoice // fetch optionals attributes and labels $this->fetch_optionals(); - if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; + if ($this->statut == self::STATUS_DRAFT) { + $this->brouillon = 1; + } $result = $this->fetch_lines(); - if ($result < 0) - { + if ($result < 0) { $this->error = $this->db->lasterror(); return -3; } @@ -783,14 +787,11 @@ class FactureFournisseur extends CommonInvoice dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); $resql_rows = $this->db->query($sql); - if ($resql_rows) - { + if ($resql_rows) { $num_rows = $this->db->num_rows($resql_rows); - if ($num_rows) - { + if ($num_rows) { $i = 0; - while ($i < $num_rows) - { + while ($i < $num_rows) { $obj = $this->db->fetch_object($resql_rows); $line = new SupplierInvoiceLine($this->db); @@ -877,37 +878,95 @@ class FactureFournisseur extends CommonInvoice $error = 0; // Clean parameters - if (empty($this->type)) $this->type = self::TYPE_STANDARD; - if (isset($this->ref)) $this->ref = trim($this->ref); - if (isset($this->ref_supplier)) $this->ref_supplier = trim($this->ref_supplier); - if (isset($this->entity)) $this->entity = trim($this->entity); - if (isset($this->type)) $this->type = trim($this->type); - if (isset($this->fk_soc)) $this->fk_soc = trim($this->fk_soc); - if (isset($this->label)) $this->label = trim($this->label); - if (isset($this->libelle)) $this->libelle = trim($this->libelle); // deprecated - if (isset($this->paye)) $this->paye = trim($this->paye); - if (isset($this->amount)) $this->amount = trim($this->amount); - if (isset($this->remise)) $this->remise = trim($this->remise); - if (isset($this->close_code)) $this->close_code = trim($this->close_code); - if (isset($this->close_note)) $this->close_note = trim($this->close_note); - if (isset($this->tva)) $this->tva = trim($this->tva); - if (isset($this->localtax1)) $this->localtax1 = trim($this->localtax1); - if (isset($this->localtax2)) $this->localtax2 = trim($this->localtax2); - if (empty($this->total_ht)) $this->total_ht = 0; - if (empty($this->total_tva)) $this->total_tva = 0; + if (empty($this->type)) { + $this->type = self::TYPE_STANDARD; + } + if (isset($this->ref)) { + $this->ref = trim($this->ref); + } + if (isset($this->ref_supplier)) { + $this->ref_supplier = trim($this->ref_supplier); + } + if (isset($this->entity)) { + $this->entity = trim($this->entity); + } + if (isset($this->type)) { + $this->type = trim($this->type); + } + if (isset($this->fk_soc)) { + $this->fk_soc = trim($this->fk_soc); + } + if (isset($this->label)) { + $this->label = trim($this->label); + } + if (isset($this->libelle)) { + $this->libelle = trim($this->libelle); // deprecated + } + if (isset($this->paye)) { + $this->paye = trim($this->paye); + } + if (isset($this->amount)) { + $this->amount = trim($this->amount); + } + if (isset($this->remise)) { + $this->remise = trim($this->remise); + } + if (isset($this->close_code)) { + $this->close_code = trim($this->close_code); + } + if (isset($this->close_note)) { + $this->close_note = trim($this->close_note); + } + if (isset($this->tva)) { + $this->tva = trim($this->tva); + } + if (isset($this->localtax1)) { + $this->localtax1 = trim($this->localtax1); + } + if (isset($this->localtax2)) { + $this->localtax2 = trim($this->localtax2); + } + if (empty($this->total_ht)) { + $this->total_ht = 0; + } + if (empty($this->total_tva)) { + $this->total_tva = 0; + } // if (isset($this->total_localtax1)) $this->total_localtax1=trim($this->total_localtax1); // if (isset($this->total_localtax2)) $this->total_localtax2=trim($this->total_localtax2); - if (isset($this->total_ttc)) $this->total_ttc = trim($this->total_ttc); - if (isset($this->statut)) $this->statut = (int) $this->statut; - if (isset($this->author)) $this->author = trim($this->author); - if (isset($this->fk_user_valid)) $this->fk_user_valid = trim($this->fk_user_valid); - if (isset($this->fk_facture_source)) $this->fk_facture_source = trim($this->fk_facture_source); - if (isset($this->fk_project)) $this->fk_project = trim($this->fk_project); - if (isset($this->cond_reglement_id)) $this->cond_reglement_id = trim($this->cond_reglement_id); - if (isset($this->note_private)) $this->note = trim($this->note_private); - if (isset($this->note_public)) $this->note_public = trim($this->note_public); - if (isset($this->model_pdf)) $this->model_pdf = trim($this->model_pdf); - if (isset($this->import_key)) $this->import_key = trim($this->import_key); + if (isset($this->total_ttc)) { + $this->total_ttc = trim($this->total_ttc); + } + if (isset($this->statut)) { + $this->statut = (int) $this->statut; + } + if (isset($this->author)) { + $this->author = trim($this->author); + } + if (isset($this->fk_user_valid)) { + $this->fk_user_valid = trim($this->fk_user_valid); + } + if (isset($this->fk_facture_source)) { + $this->fk_facture_source = trim($this->fk_facture_source); + } + if (isset($this->fk_project)) { + $this->fk_project = trim($this->fk_project); + } + if (isset($this->cond_reglement_id)) { + $this->cond_reglement_id = trim($this->cond_reglement_id); + } + if (isset($this->note_private)) { + $this->note = trim($this->note_private); + } + if (isset($this->note_public)) { + $this->note_public = trim($this->note_public); + } + if (isset($this->model_pdf)) { + $this->model_pdf = trim($this->model_pdf); + } + if (isset($this->import_key)) { + $this->import_key = trim($this->import_key); + } // Check parameters @@ -922,7 +981,9 @@ class FactureFournisseur extends CommonInvoice $sql .= " fk_soc=".(isset($this->fk_soc) ? $this->fk_soc : "null").","; $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql .= " datef=".(dol_strlen($this->date) != 0 ? "'".$this->db->idate($this->date)."'" : 'null').","; - if (dol_strlen($this->tms) != 0) $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + if (dol_strlen($this->tms) != 0) { + $sql .= " tms=".(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').","; + } $sql .= " libelle=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; $sql .= " paye=".(isset($this->paye) ? $this->paye : "null").","; $sql .= " amount=".(isset($this->amount) ? $this->amount : "null").","; @@ -963,31 +1024,27 @@ class FactureFournisseur extends CommonInvoice } } - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error) - { - if (!$notrigger) - { + if (!$error) { + if (!$notrigger) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_UPDATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } } // Commit or rollback - if ($error) - { - foreach ($this->errors as $errmsg) - { + if ($error) { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -1019,10 +1076,8 @@ class FactureFournisseur extends CommonInvoice $remise = new DiscountAbsolute($this->db); $result = $remise->fetch($idremise); - if ($result > 0) - { - if ($remise->fk_invoice_supplier) // Protection against multiple submission - { + if ($result > 0) { + if ($remise->fk_invoice_supplier) { // Protection against multiple submission $this->error = $langs->trans("ErrorDiscountAlreadyUsed"); $this->db->rollback(); return -5; @@ -1043,8 +1098,7 @@ class FactureFournisseur extends CommonInvoice $facligne->info_bits = 2; // Get buy/cost price of invoice that is source of discount - if ($remise->fk_invoice_supplier_source > 0) - { + if ($remise->fk_invoice_supplier_source > 0) { $srcinvoice = new FactureFournisseur($this->db); $srcinvoice->fetch($remise->fk_invoice_supplier_source); $totalcostpriceofinvoice = 0; @@ -1064,15 +1118,12 @@ class FactureFournisseur extends CommonInvoice $facligne->multicurrency_total_ttc = -$remise->multicurrency_total_ttc; $lineid = $facligne->insert(); - if ($lineid > 0) - { + if ($lineid > 0) { $result = $this->update_price(1); - if ($result > 0) - { + if ($result > 0) { // Create link between discount and invoice line $result = $remise->link_to_invoice($lineid, 0, 'supplier'); - if ($result < 0) - { + if ($result < 0) { $this->error = $remise->error; $this->db->rollback(); return -4; @@ -1117,12 +1168,10 @@ class FactureFournisseur extends CommonInvoice $error = 0; $this->db->begin(); - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_DELETE', $user); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -1; } @@ -1156,8 +1205,7 @@ class FactureFournisseur extends CommonInvoice } } - if (!$error) - { + if (!$error) { $main = MAIN_DB_PREFIX.'facture_fourn_det'; $ef = $main."_extrafields"; $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_facture_fourn = $rowid)"; @@ -1165,8 +1213,7 @@ class FactureFournisseur extends CommonInvoice $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';'; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resqlef && $resql) - { + if ($resqlef && $resql) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn WHERE rowid = '.$rowid; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql2 = $this->db->query($sql); @@ -1178,47 +1225,43 @@ class FactureFournisseur extends CommonInvoice } } - if (!$error) - { + if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { // Delete linked object $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } } - if (!$error) - { + if (!$error) { // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive $this->deleteEcmFiles(); // We remove directory - if ($conf->fournisseur->facture->dir_output) - { + if ($conf->fournisseur->facture->dir_output) { include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $ref = dol_sanitizeFileName($this->ref); $dir = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoive_supplier').$ref; $file = $dir."/".$ref.".pdf"; - if (file_exists($file)) - { - if (!dol_delete_file($file, 0, 0, 0, $this)) // For triggers - { + if (file_exists($file)) { + if (!dol_delete_file($file, 0, 0, 0, $this)) { // For triggers $this->error = 'ErrorFailToDeleteFile'; $error++; } } - if (file_exists($dir)) - { + if (file_exists($dir)) { $res = @dol_delete_dir_recursive($dir); - if (!$res) - { + if (!$res) { $this->error = 'ErrorFailToDeleteDir'; $error++; } @@ -1227,18 +1270,15 @@ class FactureFournisseur extends CommonInvoice } // Remove extrafields - if (!$error) - { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); } } - if (!$error) - { + if (!$error) { dol_syslog(get_class($this)."::delete $this->id by $user->id", LOG_DEBUG); $this->db->commit(); return 1; @@ -1289,11 +1329,12 @@ class FactureFournisseur extends CommonInvoice dol_syslog("FactureFournisseur::set_paid", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_PAYED', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } else { $error++; @@ -1301,8 +1342,7 @@ class FactureFournisseur extends CommonInvoice dol_print_error($this->db); } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -1350,11 +1390,12 @@ class FactureFournisseur extends CommonInvoice dol_syslog("FactureFournisseur::set_unpaid", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_UNPAYED', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } else { $error++; @@ -1362,8 +1403,7 @@ class FactureFournisseur extends CommonInvoice dol_syslog("FactureFournisseur::set_unpaid ".$this->error); } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -1397,19 +1437,16 @@ class FactureFournisseur extends CommonInvoice $this->fetch_lines(); // Check parameters - if ($this->statut > self::STATUS_DRAFT) // This is to avoid to validate twice (avoid errors on logs and stock management) - { + if ($this->statut > self::STATUS_DRAFT) { // This is to avoid to validate twice (avoid errors on logs and stock management) dol_syslog(get_class($this)."::validate no draft status", LOG_WARNING); return 0; } - if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->ref_supplier)) - { + if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->ref_supplier)) { $langs->load("errors"); $this->error = $langs->trans("ErrorFieldFormat", $langs->transnoentities("RefSupplier")).'. '.$langs->trans('RemoveString', $langs->transnoentitiesnoconv("CopyOf")); return -1; } - if (count($this->lines) <= 0) - { + if (count($this->lines) <= 0) { $langs->load("errors"); $this->error = $langs->trans("ErrorObjectMustHaveLinesToBeValidated", $this->ref); return -1; @@ -1418,11 +1455,9 @@ class FactureFournisseur extends CommonInvoice $this->db->begin(); // Define new ref - if ($force_number) - { + if ($force_number) { $num = $force_number; - } elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life - { + } elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($this->thirdparty); } else { $num = $this->ref; @@ -1435,71 +1470,72 @@ class FactureFournisseur extends CommonInvoice dol_syslog(get_class($this)."::validate", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { // Si on incrémente le produit principal et ses composants à la validation de facture fournisseur - if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) - { + if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); $cpt = count($this->lines); - for ($i = 0; $i < $cpt; $i++) - { - if ($this->lines[$i]->fk_product > 0) - { + for ($i = 0; $i < $cpt; $i++) { + if ($this->lines[$i]->fk_product > 0) { $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We increase stock for product $up_ht_disc = $this->lines[$i]->pu_ht; - if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); - if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num)); - else $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num)); - if ($result < 0) { $error++; } + if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) { + $up_ht_disc = price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); + } + if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num)); + } else { + $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num)); + } + if ($result < 0) { + $error++; + } unset($this->line); } } } // Triggers call - if (!$error && empty($notrigger)) - { + if (!$error && empty($notrigger)) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_VALIDATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if (!$error) - { + if (!$error) { $this->oldref = $this->ref; // Rename directory if dir was a temporary ref - if (preg_match('/^[\(]?PROV/i', $this->ref)) - { + if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'fournisseur/facture/".get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'fournisseur/facture/".get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$this->db->escape($this->ref)."' and entity = ".$conf->entity; $resql = $this->db->query($sql); - if (!$resql) { $error++; $this->error = $this->db->lasterror(); } + if (!$resql) { + $error++; $this->error = $this->db->lasterror(); + } // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); $dirsource = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$oldref; $dirdest = $conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$newref; - if (!$error && file_exists($dirsource)) - { + if (!$error && file_exists($dirsource)) { dol_syslog(get_class($this)."::validate rename dir ".$dirsource." into ".$dirdest); - if (@rename($dirsource, $dirdest)) - { + if (@rename($dirsource, $dirdest)) { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref $listoffiles = dol_dir_list($conf->fournisseur->facture->dir_output.'/'.get_exdir($this->id, 2, 0, 0, $this, 'invoice_supplier').$newref, 'files', 1, '^'.preg_quote($oldref, '/')); - foreach ($listoffiles as $fileentry) - { + foreach ($listoffiles as $fileentry) { $dirsource = $fileentry['name']; $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource); $dirsource = $fileentry['path'].'/'.$dirsource; @@ -1512,15 +1548,13 @@ class FactureFournisseur extends CommonInvoice } // Set new ref and define current statut - if (!$error) - { + if (!$error) { $this->ref = $num; $this->statut = self::STATUS_VALIDATED; //$this->date_validation=$now; this is stored into log table } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -1548,8 +1582,7 @@ class FactureFournisseur extends CommonInvoice $error = 0; - if ($this->statut == self::STATUS_DRAFT) - { + if ($this->statut == self::STATUS_DRAFT) { dol_syslog(__METHOD__." already draft status", LOG_WARNING); return 0; } @@ -1563,42 +1596,40 @@ class FactureFournisseur extends CommonInvoice $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); - if ($result) - { - if (!$error) - { + if ($result) { + if (!$error) { $this->oldcopy = clone $this; } // Si on incremente le produit principal et ses composants a la validation de facture fournisseur, on decremente - if ($result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) - { + if ($result >= 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); $cpt = count($this->lines); - for ($i = 0; $i < $cpt; $i++) - { - if ($this->lines[$i]->fk_product > 0) - { + for ($i = 0; $i < $cpt; $i++) { + if ($this->lines[$i]->fk_product > 0) { $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We increase stock for product - if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref)); - else $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref)); + if ($this->type == FactureFournisseur::TYPE_CREDIT_NOTE) { + $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref)); + } else { + $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr", $this->ref)); + } } } } // Triggers call - if (!$error && empty($notrigger)) - { + if (!$error && empty($notrigger)) { // Call trigger $result = $this->call_trigger('BILL_SUPPLIER_UNVALIDATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } - if ($error == 0) - { + if ($error == 0) { $this->db->commit(); return 1; } else { @@ -1652,17 +1683,32 @@ class FactureFournisseur extends CommonInvoice 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'; - if ($this->statut == self::STATUS_DRAFT) - { + if ($this->statut == self::STATUS_DRAFT) { // Clean parameters - if (empty($remise_percent)) $remise_percent = 0; - if (empty($qty)) $qty = 0; - if (empty($info_bits)) $info_bits = 0; - if (empty($rang)) $rang = 0; - if (empty($ventil)) $ventil = 0; - if (empty($txtva)) $txtva = 0; - if (empty($txlocaltax1)) $txlocaltax1 = 0; - if (empty($txlocaltax2)) $txlocaltax2 = 0; + if (empty($remise_percent)) { + $remise_percent = 0; + } + if (empty($qty)) { + $qty = 0; + } + if (empty($info_bits)) { + $info_bits = 0; + } + if (empty($rang)) { + $rang = 0; + } + if (empty($ventil)) { + $ventil = 0; + } + if (empty($txtva)) { + $txtva = 0; + } + if (empty($txlocaltax1)) { + $txlocaltax1 = 0; + } + if (empty($txlocaltax2)) { + $txlocaltax2 = 0; + } $remise_percent = price2num($remise_percent); $qty = price2num($qty); @@ -1681,15 +1727,12 @@ class FactureFournisseur extends CommonInvoice $this->db->begin(); - if ($fk_product > 0) - { - if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) - { + if ($fk_product > 0) { + if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) { // Check quantity is enough dol_syslog(get_class($this)."::addline we check supplier prices fk_product=".$fk_product." qty=".$qty." ref_supplier=".$ref_supplier); $prod = new Product($this->db, $fk_product); - if ($prod->fetch($fk_product) > 0) - { + if ($prod->fetch($fk_product) > 0) { $product_type = $prod->type; $label = $prod->label; $fk_prod_fourn_price = 0; @@ -1697,16 +1740,17 @@ class FactureFournisseur extends CommonInvoice // We use 'none' instead of $ref_supplier, because $ref_supplier may not exists anymore. So we will take the first supplier price ok. // If we want a dedicated supplier price, we must provide $fk_prod_fourn_price. $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product, 'none', ($this->fk_soc ? $this->fk_soc : $this->socid)); // Search on couple $fk_prod_fourn_price/$qty first, then on triplet $qty/$fk_product/$ref_supplier/$this->fk_soc - if ($result > 0) - { - if (empty($pu)) $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice + if ($result > 0) { + if (empty($pu)) { + $pu = $prod->fourn_pu; // Unit price supplier price set by get_buyprice + } $ref_supplier = $prod->ref_supplier; // Ref supplier price set by get_buyprice // is remise percent not keyed but present for the product we add it - if ($remise_percent == 0 && $prod->remise_percent != 0) + if ($remise_percent == 0 && $prod->remise_percent != 0) { $remise_percent = $prod->remise_percent; + } } - if ($result == 0) // If result == 0, we failed to found the supplier reference price - { + if ($result == 0) { // If result == 0, we failed to found the supplier reference price $langs->load("errors"); $this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier"); $this->db->rollback(); @@ -1715,16 +1759,14 @@ class FactureFournisseur extends CommonInvoice //$ref = $prod->ref_fourn; // We do not overwrite ref supplier price return -1; } - if ($result == -1) - { + if ($result == -1) { $langs->load("errors"); $this->error = "Ref ".$prod->ref." ".$langs->trans("ErrorQtyTooLowForThisSupplier"); $this->db->rollback(); dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_DEBUG); return -1; } - if ($result < -1) - { + if ($result < -1) { $this->error = $prod->error; $this->db->rollback(); dol_syslog(get_class($this)."::addline result=".$result." - ".$this->error, LOG_ERR); @@ -1749,8 +1791,7 @@ class FactureFournisseur extends CommonInvoice // Clean vat code $reg = array(); $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $txtva, $reg)) - { + if (preg_match('/\((.*)\)/', $txtva, $reg)) { $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } @@ -1775,10 +1816,11 @@ class FactureFournisseur extends CommonInvoice $pu_ht_devise = $tabprice[19]; // Check parameters - if ($type < 0) return -1; + if ($type < 0) { + return -1; + } - if ($rang < 0) - { + if ($rang < 0) { $rangmax = $this->line_max(); $rang = $rangmax + 1; } @@ -1837,15 +1879,15 @@ class FactureFournisseur extends CommonInvoice } $result = $this->line->insert($notrigger); - if ($result > 0) - { + if ($result > 0) { // Reorder if child line - if (!empty($fk_parent_line)) $this->line_order(true, 'DESC'); + if (!empty($fk_parent_line)) { + $this->line_order(true, 'DESC'); + } // Mise a jour informations denormalisees au niveau de la facture meme $result = $this->update_price(1, 'auto', 0, $this->thirdparty); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. - if ($result > 0) - { + if ($result > 0) { $this->db->commit(); return $this->line->id; } else { @@ -1902,7 +1944,9 @@ class FactureFournisseur extends CommonInvoice // Check parameters //if (! is_numeric($pu) || ! is_numeric($qty)) return -1; - if ($type < 0) return -1; + if ($type < 0) { + return -1; + } if ($date_start && $date_end && $date_start > $date_end) { $langs->load("errors"); @@ -1911,9 +1955,15 @@ class FactureFournisseur extends CommonInvoice } // Clean parameters - if (empty($vatrate)) $vatrate = 0; - if (empty($txlocaltax1)) $txlocaltax1 = 0; - if (empty($txlocaltax2)) $txlocaltax2 = 0; + if (empty($vatrate)) { + $vatrate = 0; + } + if (empty($txlocaltax1)) { + $txlocaltax1 = 0; + } + if (empty($txlocaltax2)) { + $txlocaltax2 = 0; + } $txlocaltax1 = price2num($txlocaltax1); $txlocaltax2 = price2num($txlocaltax2); @@ -1929,8 +1979,7 @@ class FactureFournisseur extends CommonInvoice // Clean vat code $vat_src_code = ''; - if (preg_match('/\((.*)\)/', $vatrate, $reg)) - { + if (preg_match('/\((.*)\)/', $vatrate, $reg)) { $vat_src_code = $reg[1]; $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. } @@ -1951,10 +2000,11 @@ class FactureFournisseur extends CommonInvoice $multicurrency_total_ttc = $tabprice[18]; $pu_ht_devise = $tabprice[19]; - if (empty($info_bits)) $info_bits = 0; + if (empty($info_bits)) { + $info_bits = 0; + } - if ($idproduct) - { + if ($idproduct) { $product = new Product($this->db); $result = $product->fetch($idproduct); $product_type = $product->type; @@ -2046,8 +2096,7 @@ class FactureFournisseur extends CommonInvoice dol_syslog(get_class($this)."::deleteline", LOG_DEBUG); $result = $this->db->query($sql); - if (!$result) - { + if (!$result) { $this->error = $this->db->error(); $this->db->rollback(); return -2; @@ -2068,8 +2117,7 @@ class FactureFournisseur extends CommonInvoice } else { $res = $this->update_price(); - if ($res > 0) - { + if ($res > 0) { $this->db->commit(); return 1; } else { @@ -2095,26 +2143,21 @@ class FactureFournisseur extends CommonInvoice $sql .= ' WHERE c.rowid = '.$id; $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { + if ($result) { + if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - if ($obj->fk_user_author) - { + if ($obj->fk_user_author) { $cuser = new User($this->db); $cuser->fetch($obj->fk_user_author); $this->user_creation = $cuser; } - if ($obj->fk_user_valid) - { + if ($obj->fk_user_valid) { $vuser = new User($this->db); $vuser->fetch($obj->fk_user_valid); $this->user_validation = $vuser; } - if ($obj->fk_user_modif) - { + if ($obj->fk_user_modif) { $muser = new User($this->db); $muser->fetch($obj->fk_user_modif); $this->user_modification = $muser; @@ -2155,15 +2198,15 @@ class FactureFournisseur extends CommonInvoice $sql .= " AND f.paye = 0"; // Pas classee payee completement $sql .= " AND pf.fk_paiementfourn IS NULL"; // Aucun paiement deja fait $sql .= " AND ff.fk_statut IS NULL"; // Renvoi vrai si pas facture de remplacement - if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid; + if ($socid > 0) { + $sql .= " AND f.fk_soc = ".$socid; + } $sql .= " ORDER BY f.ref"; dol_syslog(get_class($this)."::list_replacable_supplier_invoices", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $return[$obj->rowid] = array( 'id' => $obj->rowid, 'ref' => $obj->ref, @@ -2203,20 +2246,23 @@ class FactureFournisseur extends CommonInvoice $sql .= " AND NOT EXISTS (SELECT rowid from ".MAIN_DB_PREFIX."facture_fourn as ff WHERE f.rowid = ff.fk_facture_source"; $sql .= " AND ff.type=".self::TYPE_REPLACEMENT.")"; $sql .= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir - if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid; + if ($socid > 0) { + $sql .= " AND f.fk_soc = ".$socid; + } $sql .= " ORDER BY f.ref"; dol_syslog(get_class($this)."::list_qualified_avoir_supplier_invoices", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $qualified = 0; - if ($obj->fk_statut == self::STATUS_VALIDATED) $qualified = 1; - if ($obj->fk_statut == self::STATUS_CLOSED) $qualified = 1; - if ($qualified) - { + if ($obj->fk_statut == self::STATUS_VALIDATED) { + $qualified = 1; + } + if ($obj->fk_statut == self::STATUS_CLOSED) { + $qualified = 1; + } + if ($qualified) { $paymentornot = ($obj->fk_paiementfourn ? 1 : 0); $return[$obj->rowid] = array('ref'=>$obj->ref, 'status'=>$obj->fk_statut, 'type'=>$obj->type, 'paye'=>$obj->paye, 'paymentornot'=>$paymentornot); } @@ -2243,16 +2289,21 @@ class FactureFournisseur extends CommonInvoice $sql = 'SELECT ff.rowid, ff.date_lim_reglement as datefin, ff.fk_statut'; $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as ff'; - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$user->socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= ' WHERE ff.paye=0'; $sql .= ' AND ff.fk_statut > 0'; $sql .= " AND ff.entity = ".$conf->entity; - if ($user->socid) $sql .= ' AND ff.fk_soc = '.$user->socid; - if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND ff.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + if ($user->socid) { + $sql .= ' AND ff.fk_soc = '.$user->socid; + } + if (!$user->rights->societe->client->voir && !$user->socid) { + $sql .= " AND ff.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + } $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $langs->load("bills"); $now = dol_now(); @@ -2266,8 +2317,7 @@ class FactureFournisseur extends CommonInvoice $facturestatic = new FactureFournisseur($this->db); - while ($obj = $this->db->fetch_object($resql)) - { + while ($obj = $this->db->fetch_object($resql)) { $response->nbtodo++; $facturestatic->date_echeance = $this->db->jdate($obj->datefin); @@ -2307,56 +2357,84 @@ class FactureFournisseur extends CommonInvoice $result = ''; - if ($option == 'withdraw') $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id.'&type=bank-transfer'; - elseif ($option == 'document') $url = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$this->id; - else $url = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$this->id; + if ($option == 'withdraw') { + $url = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$this->id.'&type=bank-transfer'; + } elseif ($option == 'document') { + $url = DOL_URL_ROOT.'/fourn/facture/document.php?facid='.$this->id; + } else { + $url = DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$this->id; + } - if ($short) return $url; + if ($short) { + return $url; + } - if ($option !== 'nolink') - { + if ($option !== 'nolink') { // Add param to save lastsearch_values or not $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); - if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1; - if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1'; + if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { + $add_save_lastsearch_values = 1; + } + if ($add_save_lastsearch_values) { + $url .= '&save_lastsearch_values=1'; + } } $picto = $this->picto; - if ($this->type == self::TYPE_REPLACEMENT) $picto .= 'r'; // Replacement invoice - if ($this->type == self::TYPE_CREDIT_NOTE) $picto .= 'a'; // Credit note - if ($this->type == self::TYPE_DEPOSIT) $picto .= 'd'; // Deposit invoice + if ($this->type == self::TYPE_REPLACEMENT) { + $picto .= 'r'; // Replacement invoice + } + if ($this->type == self::TYPE_CREDIT_NOTE) { + $picto .= 'a'; // Credit note + } + if ($this->type == self::TYPE_DEPOSIT) { + $picto .= 'd'; // Deposit invoice + } $label = img_picto('', $this->picto).' '.$langs->trans("SupplierInvoice").''; - if ($this->type == self::TYPE_REPLACEMENT) $label = ''.$langs->transnoentitiesnoconv("InvoiceReplace").''; - elseif ($this->type == self::TYPE_CREDIT_NOTE) $label = ''.$langs->transnoentitiesnoconv("CreditNote").''; - elseif ($this->type == self::TYPE_DEPOSIT) $label = ''.$langs->transnoentitiesnoconv("Deposit").''; - if (!empty($this->ref)) + if ($this->type == self::TYPE_REPLACEMENT) { + $label = ''.$langs->transnoentitiesnoconv("InvoiceReplace").''; + } elseif ($this->type == self::TYPE_CREDIT_NOTE) { + $label = ''.$langs->transnoentitiesnoconv("CreditNote").''; + } elseif ($this->type == self::TYPE_DEPOSIT) { + $label = ''.$langs->transnoentitiesnoconv("Deposit").''; + } + if (!empty($this->ref)) { $label .= '
'.$langs->trans('Ref').': '.$this->ref; - if (!empty($this->ref_supplier)) + } + if (!empty($this->ref_supplier)) { $label .= '
'.$langs->trans('RefSupplier').': '.$this->ref_supplier; - if (!empty($this->label)) + } + if (!empty($this->label)) { $label .= '
'.$langs->trans('Label').': '.$this->label; - if (!empty($this->date)) + } + if (!empty($this->date)) { $label .= '
'.$langs->trans('Date').': '.dol_print_date($this->date, 'day'); - if (!empty($this->total_ht)) + } + if (!empty($this->total_ht)) { $label .= '
'.$langs->trans('AmountHT').': '.price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency); - if (!empty($this->total_tva)) + } + if (!empty($this->total_tva)) { $label .= '
'.$langs->trans('AmountVAT').': '.price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency); - if (!empty($this->total_ttc)) + } + if (!empty($this->total_ttc)) { $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); - if ($moretitle) $label .= ' - '.$moretitle; + } + if ($moretitle) { + $label .= ' - '.$moretitle; + } if (isset($this->statut) && isset($this->alreadypaid)) { $label .= '
'.$langs->trans("Status").": ".$this->getLibStatut(5, $this->alreadypaid); } $ref = $this->ref; - if (empty($ref)) $ref = $this->id; + if (empty($ref)) { + $ref = $this->id; + } $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("ShowSupplierInvoice"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } @@ -2369,15 +2447,17 @@ class FactureFournisseur extends CommonInvoice $linkend = '
'; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= ($max ?dol_trunc($ref, $max) : $ref); + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), $picto, ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= ($max ?dol_trunc($ref, $max) : $ref); + } $result .= $linkend; - if ($addlinktonotes) - { + if ($addlinktonotes) { $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private); - if ($txttoshow) - { + if ($txttoshow) { $notetoshow = $langs->trans("ViewPrivateNote").':
'.dol_string_nohtmltag($txttoshow, 1); $result .= ' '; $result .= ''; @@ -2406,7 +2486,9 @@ class FactureFournisseur extends CommonInvoice $langs->load("orders"); // Clean parameters (if not defined or using deprecated value) - if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER = 'mod_facture_fournisseur_cactus'; + if (empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER)) { + $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER = 'mod_facture_fournisseur_cactus'; + } $mybool = false; @@ -2432,8 +2514,7 @@ class FactureFournisseur extends CommonInvoice $numref = ""; $numref = $obj->getNumRef($soc, $this, $mode); - if ($numref != "") - { + if ($numref != "") { return $numref; } else { $this->error = $obj->error; @@ -2467,12 +2548,10 @@ class FactureFournisseur extends CommonInvoice $sql .= $this->db->plimit(100); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num_prods = $this->db->num_rows($resql); $i = 0; - while ($i < $num_prods) - { + while ($i < $num_prods) { $i++; $row = $this->db->fetch_row($resql); $prodids[$i] = $row[0]; @@ -2496,13 +2575,11 @@ class FactureFournisseur extends CommonInvoice $this->multicurrency_tx = 1; $this->multicurrency_code = $conf->currency; - if (empty($option) || $option != 'nolines') - { + if (empty($option) || $option != 'nolines') { // Lines $nbp = 5; $xnbp = 0; - while ($xnbp < $nbp) - { + while ($xnbp < $nbp) { $line = new SupplierInvoiceLine($this->db); $line->desc = $langs->trans("Description")." ".$xnbp; $line->qty = 1; @@ -2512,8 +2589,7 @@ class FactureFournisseur extends CommonInvoice $line->tva_tx = 19.6; $line->localtax1_tx = 0; $line->localtax2_tx = 0; - if ($xnbp == 2) - { + if ($xnbp == 2) { $line->total_ht = 50; $line->total_ttc = 59.8; $line->total_tva = 9.8; @@ -2525,8 +2601,7 @@ class FactureFournisseur extends CommonInvoice $line->remise_percent = 0; } - if ($num_prods > 0) - { + if ($num_prods > 0) { $prodid = mt_rand(1, $num_prods); $line->fk_product = $prodids[$prodid]; } @@ -2566,8 +2641,7 @@ class FactureFournisseur extends CommonInvoice $sql = "SELECT count(f.rowid) as nb"; $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid"; - if (!$user->rights->societe->client->voir && !$user->socid) - { + if (!$user->rights->societe->client->voir && !$user->socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; $sql .= " WHERE sc.fk_user = ".$user->id; $clause = "AND"; @@ -2575,10 +2649,8 @@ class FactureFournisseur extends CommonInvoice $sql .= " ".$clause." f.entity = ".$conf->entity; $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->nb["supplier_invoices"] = $obj->nb; } $this->db->free($resql); @@ -2629,10 +2701,8 @@ class FactureFournisseur extends CommonInvoice $object->close_note = ''; // Loop on each line of new invoice - foreach ($object->lines as $i => $line) - { - if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x02) == 0x02) // We do not clone line of discounts - { + foreach ($object->lines as $i => $line) { + if (isset($object->lines[$i]->info_bits) && ($object->lines[$i]->info_bits & 0x02) == 0x02) { // We do not clone line of discounts unset($object->lines[$i]); } } @@ -2642,22 +2712,19 @@ class FactureFournisseur extends CommonInvoice $result = $object->create($user); // Other options - if ($result < 0) - { + if ($result < 0) { $this->error = $object->error; $this->errors = $object->errors; $error++; } - if (!$error) - { + if (!$error) { } unset($object->context['createfromclone']); // End - if (!$error) - { + if (!$error) { $this->db->commit(); return $object->id; } else { @@ -2685,18 +2752,15 @@ class FactureFournisseur extends CommonInvoice $outputlangs->load("products"); // Set the model on the model name to use - if (empty($modele)) - { - if (!empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) - { + if (empty($modele)) { + if (!empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF)) { $modele = $conf->global->INVOICE_SUPPLIER_ADDON_PDF; } else { $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation } } - if (empty($modele)) - { + if (empty($modele)) { return 0; } else { $modelpath = "core/modules/supplier_invoice/doc/"; @@ -2764,7 +2828,9 @@ class FactureFournisseur extends CommonInvoice $resql = $this->db->query($sql); if (!empty($resql)) { $obj = $this->db->fetch_object($resql); - if (!empty($obj->fk_invoice_supplier)) $isUsed = true; + if (!empty($obj->fk_invoice_supplier)) { + $isUsed = true; + } } return $isUsed; @@ -3111,11 +3177,9 @@ class SupplierInvoiceLine extends CommonObjectLine $this->deleteObjectLinked(); // Remove extrafields - if (!$error) - { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); } @@ -3133,8 +3197,7 @@ class SupplierInvoiceLine extends CommonObjectLine } } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -3157,22 +3220,31 @@ class SupplierInvoiceLine extends CommonObjectLine $qty = price2num($this->qty); // Check parameters - if (empty($this->qty)) $this->qty = 0; + if (empty($this->qty)) { + $this->qty = 0; + } if ($this->product_type < 0) { return -1; } // Clean parameters - if (empty($this->remise_percent)) $this->remise_percent = 0; - if (empty($this->tva_tx)) $this->tva_tx = 0; - if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; - if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; + if (empty($this->remise_percent)) { + $this->remise_percent = 0; + } + if (empty($this->tva_tx)) { + $this->tva_tx = 0; + } + if (empty($this->localtax1_tx)) { + $this->localtax1_tx = 0; + } + if (empty($this->localtax2_tx)) { + $this->localtax2_tx = 0; + } $this->db->begin(); - if (empty($this->fk_product)) - { + if (empty($this->fk_product)) { $fk_product = "null"; } else { $fk_product = $this->fk_product; @@ -3229,17 +3301,14 @@ class SupplierInvoiceLine extends CommonObjectLine $this->rowid = $this->id; $error = 0; - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { global $langs, $user; // Call trigger @@ -3275,41 +3344,78 @@ class SupplierInvoiceLine extends CommonObjectLine // Clean parameters $this->desc = trim($this->desc); - if (empty($this->tva_tx)) $this->tva_tx = 0; - if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; - if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; - if (empty($this->localtax1_type)) $this->localtax1_type = '0'; - if (empty($this->localtax2_type)) $this->localtax2_type = '0'; - if (empty($this->total_tva)) $this->total_tva = 0; - if (empty($this->total_localtax1)) $this->total_localtax1 = 0; - if (empty($this->total_localtax2)) $this->total_localtax2 = 0; - if (empty($this->rang)) $this->rang = 0; - if (empty($this->remise_percent)) $this->remise_percent = 0; - if (empty($this->info_bits)) $this->info_bits = 0; - if (empty($this->subprice)) $this->subprice = 0; - if (empty($this->special_code)) $this->special_code = 0; - if (empty($this->fk_parent_line)) $this->fk_parent_line = 0; - if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100; + if (empty($this->tva_tx)) { + $this->tva_tx = 0; + } + if (empty($this->localtax1_tx)) { + $this->localtax1_tx = 0; + } + if (empty($this->localtax2_tx)) { + $this->localtax2_tx = 0; + } + if (empty($this->localtax1_type)) { + $this->localtax1_type = '0'; + } + if (empty($this->localtax2_type)) { + $this->localtax2_type = '0'; + } + if (empty($this->total_tva)) { + $this->total_tva = 0; + } + if (empty($this->total_localtax1)) { + $this->total_localtax1 = 0; + } + if (empty($this->total_localtax2)) { + $this->total_localtax2 = 0; + } + if (empty($this->rang)) { + $this->rang = 0; + } + if (empty($this->remise_percent)) { + $this->remise_percent = 0; + } + if (empty($this->info_bits)) { + $this->info_bits = 0; + } + if (empty($this->subprice)) { + $this->subprice = 0; + } + if (empty($this->special_code)) { + $this->special_code = 0; + } + if (empty($this->fk_parent_line)) { + $this->fk_parent_line = 0; + } + if (!isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') { + $this->situation_percent = 100; + } - if (empty($this->pa_ht)) $this->pa_ht = 0; - if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice = 0; - if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht = 0; - if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva = 0; - if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc = 0; + if (empty($this->pa_ht)) { + $this->pa_ht = 0; + } + if (empty($this->multicurrency_subprice)) { + $this->multicurrency_subprice = 0; + } + if (empty($this->multicurrency_total_ht)) { + $this->multicurrency_total_ht = 0; + } + if (empty($this->multicurrency_total_tva)) { + $this->multicurrency_total_tva = 0; + } + if (empty($this->multicurrency_total_ttc)) { + $this->multicurrency_total_ttc = 0; + } // Check parameters - if ($this->product_type < 0) - { + if ($this->product_type < 0) { $this->error = 'ErrorProductTypeMustBe0orMore'; return -1; } - if (!empty($this->fk_product)) - { + if (!empty($this->fk_product)) { // Check product exists $result = Product::isExistingObject('product', $this->fk_product); - if ($result <= 0) - { + if ($result <= 0) { $this->error = 'ErrorProductIdDoesNotExists'; return -1; } @@ -3365,26 +3471,21 @@ class SupplierInvoiceLine extends CommonObjectLine $sql .= ')'; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); $this->rowid = $this->id; // backward compatibility - if (!$error) - { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $error++; } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('LINEBILL_SUPPLIER_CREATE', $user); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -2; } @@ -3423,8 +3524,7 @@ class SupplierInvoiceLine extends CommonObjectLine dol_syslog("FactureFournisseurLigne.class.php::update_total", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->db->commit(); return 1; } else { diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 6ae9a3491ab..e0eea961b9e 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -168,14 +168,12 @@ class ProductFournisseur extends Product dol_syslog(get_class($this)."::remove_fournisseur", LOG_DEBUG); $resql2 = $this->db->query($sql); - if (!$resql2) - { + if (!$resql2) { $this->error = $this->db->lasterror(); $ok = 0; } - if ($ok) - { + if ($ok) { $this->db->commit(); return 1; } else { @@ -203,18 +201,18 @@ class ProductFournisseur extends Product // Call trigger $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_DELETE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers - if (empty($error)) - { + if (empty($error)) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; $sql .= " WHERE rowid = ".$rowid; dol_syslog(get_class($this)."::remove_product_fournisseur_price", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->lasterror(); $error++; } @@ -266,15 +264,28 @@ class ProductFournisseur extends Product //global $mysoc; // Clean parameter - if (empty($qty)) $qty = 0; - if (empty($buyprice)) $buyprice = 0; - if (empty($charges)) $charges = 0; - if (empty($availability)) $availability = 0; - if (empty($remise_percent)) $remise_percent = 0; - if (empty($supplier_reputation) || $supplier_reputation == -1) $supplier_reputation = ''; - if ($delivery_time_days != '' && !is_numeric($delivery_time_days)) $delivery_time_days = ''; - if ($price_base_type == 'TTC') - { + if (empty($qty)) { + $qty = 0; + } + if (empty($buyprice)) { + $buyprice = 0; + } + if (empty($charges)) { + $charges = 0; + } + if (empty($availability)) { + $availability = 0; + } + if (empty($remise_percent)) { + $remise_percent = 0; + } + if (empty($supplier_reputation) || $supplier_reputation == -1) { + $supplier_reputation = ''; + } + if ($delivery_time_days != '' && !is_numeric($delivery_time_days)) { + $delivery_time_days = ''; + } + if ($price_base_type == 'TTC') { $ttx = $tva_tx; $buyprice = $buyprice / (1 + ($ttx / 100)); } @@ -283,10 +294,13 @@ class ProductFournisseur extends Product $multicurrency_unitBuyPrice = null; $fk_multicurrency = null; if (!empty($conf->multicurrency->enabled)) { - if (empty($multicurrency_tx)) $multicurrency_tx = 1; - if (empty($multicurrency_buyprice)) $multicurrency_buyprice = 0; - if ($multicurrency_price_base_type == 'TTC') - { + if (empty($multicurrency_tx)) { + $multicurrency_tx = 1; + } + if (empty($multicurrency_buyprice)) { + $multicurrency_buyprice = 0; + } + if ($multicurrency_price_base_type == 'TTC') { $ttx = $tva_tx; $multicurrency_buyprice = $multicurrency_buyprice / (1 + ($ttx / 100)); } @@ -309,8 +323,7 @@ class ProductFournisseur extends Product $newvat = $tva_tx; - if (count($localtaxes_array) > 0) - { + if (count($localtaxes_array) > 0) { $localtaxtype1 = $localtaxes_array['0']; $localtax1 = $localtaxes_array['1']; $localtaxtype2 = $localtaxes_array['2']; @@ -321,26 +334,26 @@ class ProductFournisseur extends Product $localtaxtype2 = '0'; $localtax2 = get_localtax($newvat, 2); } - if (empty($localtax1)) $localtax1 = 0; // If = '' then = 0 - if (empty($localtax2)) $localtax2 = 0; // If = '' then = 0 + if (empty($localtax1)) { + $localtax1 = 0; // If = '' then = 0 + } + if (empty($localtax2)) { + $localtax2 = 0; // If = '' then = 0 + } // Check parameters - if ($buyprice != '' && !is_numeric($buyprice)) - { + if ($buyprice != '' && !is_numeric($buyprice)) { } $this->db->begin(); - if ($this->product_fourn_price_id > 0) - { + if ($this->product_fourn_price_id > 0) { // check if price already logged, if not first log current price $logPrices = $this->listProductFournisseurPriceLog($this->product_fourn_price_id); - if (is_array($logPrices) && count($logPrices) == 0) - { + if (is_array($logPrices) && count($logPrices) == 0) { $currentPfp = new self($this->db); $result = $currentPfp->fetch_product_fournisseur_price($this->product_fourn_price_id); - if ($result > 0 && $currentPfp->fourn_price != 0) - { + if ($result > 0 && $currentPfp->fourn_price != 0) { $currentPfpUser = new User($this->db); $result = $currentPfpUser->fetch($currentPfp->user_id); if ($result > 0) { @@ -387,27 +400,28 @@ class ProductFournisseur extends Product $sql .= " supplier_reputation = ".(empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").","; $sql .= " barcode = ".(empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").","; $sql .= " fk_barcode_type = ".(empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'"); - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging); + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { + $sql .= ", packaging = ".(empty($packaging) ? 1 : $packaging); + } $sql .= " WHERE rowid = ".$this->product_fourn_price_id; // TODO Add price_base_type and price_ttc dol_syslog(get_class($this).'::update_buyprice update knowing id of line = product_fourn_price_id = '.$this->product_fourn_price_id, LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { // Call trigger $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_UPDATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers - if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) - { + if (!$error && empty($conf->global->PRODUCT_PRICE_SUPPLIER_NO_LOG)) { $result = $this->logPrice($user, $now, $buyprice, $qty, $multicurrency_buyprice, $multicurrency_unitBuyPrice, $multicurrency_tx, $fk_multicurrency, $multicurrency_code); if ($result < 0) { $error++; } } - if (empty($error)) - { + if (empty($error)) { $this->db->commit(); return $this->product_fourn_price_id; } else { @@ -431,7 +445,9 @@ class ProductFournisseur extends Product $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price("; $sql .= " multicurrency_price, multicurrency_unitprice, multicurrency_tx, fk_multicurrency, multicurrency_code,"; $sql .= "datec, fk_product, fk_soc, ref_fourn, desc_fourn, fk_user, price, quantity, remise_percent, remise, unitprice, tva_tx, charges, fk_availability, default_vat_code, info_bits, entity, delivery_time_days, supplier_reputation, barcode, fk_barcode_type)"; - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", packaging"; + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { + $sql .= ", packaging"; + } $sql .= " values("; $sql .= (isset($multicurrency_buyprice) ? "'".$this->db->escape(price2num($multicurrency_buyprice))."'" : 'null').","; $sql .= (isset($multicurrency_unitBuyPrice) ? "'".$this->db->escape(price2num($multicurrency_unitBuyPrice))."'" : 'null').","; @@ -459,7 +475,9 @@ class ProductFournisseur extends Product $sql .= (empty($supplier_reputation) ? 'NULL' : "'".$this->db->escape($supplier_reputation)."'").","; $sql .= (empty($barcode) ? 'NULL' : "'".$this->db->escape($barcode)."'").","; $sql .= (empty($fk_barcode_type) ? 'NULL' : "'".$this->db->escape($fk_barcode_type)."'"); - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", ".(empty($this->packaging) ? 1 : $this->db->escape($this->packaging)); + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { + $sql .= ", ".(empty($this->packaging) ? 1 : $this->db->escape($this->packaging)); + } $sql .= ")"; $this->product_fourn_price_id = 0; @@ -483,8 +501,9 @@ class ProductFournisseur extends Product if (!$error) { // Call trigger $result = $this->call_trigger('SUPPLIER_PRODUCT_BUYPRICE_CREATE', $user); - if ($result < 0) + if ($result < 0) { $error++; + } // End call triggers if (empty($error)) { @@ -532,11 +551,9 @@ class ProductFournisseur extends Product dol_syslog(get_class($this)."::fetch_product_fournisseur_price", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $obj = $this->db->fetch_object($resql); - if ($obj) - { + if ($obj) { $this->product_fourn_price_id = $rowid; $this->id = $obj->fk_product; @@ -578,18 +595,18 @@ class ProductFournisseur extends Product if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $this->packaging = $obj->packaging; - if ($this->packaging < $this->fourn_qty) $this->packaging = $this->fourn_qty; + if ($this->packaging < $this->fourn_qty) { + $this->packaging = $this->fourn_qty; + } } - if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) - { + if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) { $priceparser = new PriceParser($this->db); $price_result = $priceparser->parseProductSupplier($this); if ($price_result >= 0) { $this->fourn_price = $price_result; //recalculation of unitprice, as probably the price changed... - if ($this->fourn_qty != 0) - { + if ($this->fourn_qty != 0) { $this->fourn_unitprice = price2num($this->fourn_price / $this->fourn_qty, 'MU'); } else { $this->fourn_unitprice = ""; @@ -629,24 +646,27 @@ class ProductFournisseur extends Product $sql .= " pfp.price, pfp.quantity, pfp.unitprice, pfp.remise_percent, pfp.remise, pfp.tva_tx, pfp.fk_availability, pfp.charges, pfp.info_bits, pfp.delivery_time_days, pfp.supplier_reputation,"; $sql .= " pfp.multicurrency_price, pfp.multicurrency_unitprice, pfp.multicurrency_tx, pfp.fk_multicurrency, pfp.multicurrency_code, pfp.datec, pfp.tms,"; $sql .= " pfp.barcode, pfp.fk_barcode_type"; - if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) $sql .= ", pfp.packaging"; + if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { + $sql .= ", pfp.packaging"; + } $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp, ".MAIN_DB_PREFIX."product as p, ".MAIN_DB_PREFIX."societe as s"; $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")"; $sql .= " AND pfp.fk_soc = s.rowid AND pfp.fk_product = p.rowid"; $sql .= " AND s.status=1"; // only enabled company selected $sql .= " AND pfp.fk_product = ".$prodid; - if (empty($sortfield)) $sql .= " ORDER BY s.nom, pfp.quantity, pfp.price"; - else $sql .= $this->db->order($sortfield, $sortorder); + if (empty($sortfield)) { + $sql .= " ORDER BY s.nom, pfp.quantity, pfp.price"; + } else { + $sql .= $this->db->order($sortfield, $sortorder); + } $sql .= $this->db->plimit($limit, $offset); dol_syslog(get_class($this)."::list_product_fournisseur_price", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $retarray = array(); - while ($record = $this->db->fetch_array($resql)) - { + while ($record = $this->db->fetch_array($resql)) { //define base attribute $prodfourn = new ProductFournisseur($this->db); @@ -683,7 +703,9 @@ class ProductFournisseur extends Product if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) { $prodfourn->packaging = $record["packaging"]; - if ($prodfourn->packaging < $prodfourn->fourn_qty) $prodfourn->packaging = $prodfourn->fourn_qty; + if ($prodfourn->packaging < $prodfourn->fourn_qty) { + $prodfourn->packaging = $prodfourn->fourn_qty; + } } if (!empty($conf->barcode->enabled)) { @@ -700,10 +722,8 @@ class ProductFournisseur extends Product } } - if (!isset($prodfourn->fourn_unitprice)) - { - if ($prodfourn->fourn_qty != 0) - { + if (!isset($prodfourn->fourn_unitprice)) { + if ($prodfourn->fourn_qty != 0) { $prodfourn->fourn_unitprice = price2num($prodfourn->fourn_price / $prodfourn->fourn_qty, 'MU'); } else { $prodfourn->fourn_unitprice = ""; @@ -735,8 +755,7 @@ class ProductFournisseur extends Product // phpcs:enable global $conf; - if (empty($prodid)) - { + if (empty($prodid)) { dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING); return 0; } @@ -771,30 +790,30 @@ class ProductFournisseur extends Product $sql .= " AND pfp.fk_product = ".$prodid; $sql .= " AND pfp.fk_soc = s.rowid"; $sql .= " AND s.status = 1"; // only enabled society - if ($qty > 0) $sql .= " AND pfp.quantity <= ".$qty; - if ($socid > 0) $sql .= ' AND pfp.fk_soc = '.$socid; + if ($qty > 0) { + $sql .= " AND pfp.quantity <= ".$qty; + } + if ($socid > 0) { + $sql .= ' AND pfp.fk_soc = '.$socid; + } dol_syslog(get_class($this)."::find_min_price_product_fournisseur", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $record_array = array(); //Store each record to array for later search of min - while ($record = $this->db->fetch_array($resql)) - { + while ($record = $this->db->fetch_array($resql)) { $record_array[] = $record; } - if (count($record_array) == 0) - { + if (count($record_array) == 0) { $this->db->free($resql); return 0; } else { $min = -1; - foreach ($record_array as $record) - { + foreach ($record_array as $record) { $fourn_price = $record["price"]; // discount calculated buy price $fourn_unitprice = $record["unitprice"] * (1 - $record["remise_percent"] / 100) - $record["remise"]; @@ -809,16 +828,14 @@ class ProductFournisseur extends Product $price_result = $priceparser->parseProductSupplier($prod_supplier); if ($price_result >= 0) { $fourn_price = price2num($price_result, 'MU'); - if ($record["quantity"] != 0) - { + if ($record["quantity"] != 0) { $fourn_unitprice = price2num($fourn_price / $record["quantity"], 'MU'); } else { $fourn_unitprice = $fourn_price; } } } - if ($fourn_unitprice < $min || $min == -1) - { + if ($fourn_unitprice < $min || $min == -1) { $this->product_fourn_price_id = $record["product_fourn_price_id"]; $this->ref_supplier = $record["ref_fourn"]; $this->ref_fourn = $record["ref_fourn"]; // deprecated @@ -874,8 +891,7 @@ class ProductFournisseur extends Product dol_syslog(get_class($this)."::setSupplierPriceExpression", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->db->commit(); return 1; } else { @@ -982,18 +998,19 @@ class ProductFournisseur extends Product $sql .= " AND pfpl.fk_user = u.rowid"; $sql .= " AND pfp.rowid = pfpl.fk_product_fournisseur"; $sql .= " AND pfpl.fk_product_fournisseur = ".$product_fourn_price_id; - if (empty($sortfield)) $sql .= " ORDER BY pfpl.datec"; - else $sql .= $this->db->order($sortfield, $sortorder); + if (empty($sortfield)) { + $sql .= " ORDER BY pfpl.datec"; + } else { + $sql .= $this->db->order($sortfield, $sortorder); + } $sql .= $this->db->plimit($limit, $offset); dol_syslog(get_class($this)."::list_product_fournisseur_price_log", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $retarray = array(); - while ($obj = $this->db->fetch_object($resql)) - { + while ($obj = $this->db->fetch_object($resql)) { $tmparray = array(); $tmparray['rowid'] = $obj->rowid; $tmparray['supplier_ref'] = $obj->supplier_ref; @@ -1126,7 +1143,9 @@ class ProductFournisseur extends Product if ($this->height) { $labelsize .= ($labelsize ? " - " : "")."".$langs->trans("Height").': '.$this->height.' '.measuringUnitString(0, 'size', $this->height_units); } - if ($labelsize) $label .= "
".$labelsize; + if ($labelsize) { + $label .= "
".$labelsize; + } $labelsurfacevolume = ""; if ($this->surface) { @@ -1135,7 +1154,9 @@ class ProductFournisseur extends Product if ($this->volume) { $labelsurfacevolume .= ($labelsurfacevolume ? " - " : "")."".$langs->trans("Volume").': '.$this->volume.' '.measuringUnitString(0, 'volume', $this->volume_units); } - if ($labelsurfacevolume) $label .= "
".$labelsurfacevolume; + if ($labelsurfacevolume) { + $label .= "
".$labelsurfacevolume; + } } if (!empty($conf->accounting->enabled) && $this->status) { diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php index cd172d08345..ceb7bb835ef 100644 --- a/htdocs/fourn/class/paiementfourn.class.php +++ b/htdocs/fourn/class/paiementfourn.class.php @@ -98,20 +98,19 @@ class PaiementFourn extends Paiement $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid'; $sql .= ' WHERE p.entity IN ('.getEntity('facture_fourn').')'; - if ($id > 0) + if ($id > 0) { $sql .= ' AND p.rowid = '.$id; - elseif ($ref) + } elseif ($ref) { $sql .= ' AND p.rowid = '.$ref; - elseif ($fk_bank) + } elseif ($fk_bank) { $sql .= ' AND p.fk_bank = '.$fk_bank; + } //print $sql; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num > 0) - { + if ($num > 0) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; @@ -166,8 +165,7 @@ class PaiementFourn extends Paiement dol_syslog(get_class($this)."::create", LOG_DEBUG); - if ($way == 'dolibarr') - { + if ($way == 'dolibarr') { $amounts = &$this->amounts; $amounts_to_update = &$this->multicurrency_amounts; } else { @@ -175,8 +173,7 @@ class PaiementFourn extends Paiement $amounts_to_update = &$this->amounts; } - foreach ($amounts as $key => $value) - { + foreach ($amounts as $key => $value) { $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value ? $value : 0, $way, 'facture_fourn'); $totalamount_converted += $value_converted; $amounts_to_update[$key] = price2num($value_converted, 'MT'); @@ -190,13 +187,11 @@ class PaiementFourn extends Paiement $this->db->begin(); - if ($totalamount <> 0) // On accepte les montants negatifs - { + if ($totalamount <> 0) { // On accepte les montants negatifs $ref = $this->getNextNumRef(is_object($thirdparty) ? $thirdparty : ''); $now = dol_now(); - if ($way == 'dolibarr') - { + if ($way == 'dolibarr') { $total = $totalamount; $mtotal = $totalamount_converted; // Maybe use price2num with MT for the converted value } else { @@ -210,28 +205,23 @@ class PaiementFourn extends Paiement $sql .= " '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_private)."', ".$user->id.", 0)"; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'paiementfourn'); // Insere tableau des montants / factures - foreach ($this->amounts as $key => $amount) - { + foreach ($this->amounts as $key => $amount) { $facid = $key; - if (is_numeric($amount) && $amount <> 0) - { + if (is_numeric($amount) && $amount <> 0) { $amount = price2num($amount); $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiementfourn_facturefourn (fk_facturefourn, fk_paiementfourn, amount, multicurrency_amount)'; $sql .= ' VALUES ('.$facid.','.$this->id.',\''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')'; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $invoice = new FactureFournisseur($this->db); $invoice->fetch($facid); // If we want to closed paid invoices - if ($closepaidinvoices) - { + if ($closepaidinvoices) { $paiement = $invoice->getSommePaiement(); //$creditnotes=$invoice->getSumCreditNotesUsed(); $creditnotes = 0; @@ -239,18 +229,20 @@ class PaiementFourn extends Paiement $deposits = 0; $alreadypayed = price2num($paiement + $creditnotes + $deposits, 'MT'); $remaintopay = price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits, 'MT'); - if ($remaintopay == 0) - { + if ($remaintopay == 0) { $result = $invoice->setPaid($user, '', ''); - } else dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing."); + } else { + dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing."); + } } // Regenerate documents of invoices - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $newlang = ''; $outputlangs = $langs; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $invoice->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $invoice->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -271,11 +263,12 @@ class PaiementFourn extends Paiement } } - if (!$error) - { + if (!$error) { // Call trigger $result = $this->call_trigger('PAYMENT_SUPPLIER_CREATE', $user); - if ($result < 0) $error++; + if ($result < 0) { + $error++; + } // End call triggers } } else { @@ -288,8 +281,7 @@ class PaiementFourn extends Paiement $error++; } - if ($totalamount <> 0 && $error == 0) // On accepte les montants negatifs - { + if ($totalamount <> 0 && $error == 0) { // On accepte les montants negatifs $this->amount = $total; $this->total = $total; $this->multicurrency_amount = $mtotal; @@ -322,10 +314,8 @@ class PaiementFourn extends Paiement // Verifier si paiement porte pas sur une facture a l'etat payee // Si c'est le cas, on refuse la suppression $billsarray = $this->getBillsArray('paye=1'); - if (is_array($billsarray)) - { - if (count($billsarray)) - { + if (is_array($billsarray)) { + if (count($billsarray)) { $this->error = "ErrorCantDeletePaymentSharedWithPayedInvoice"; $this->db->rollback(); return -1; @@ -337,12 +327,10 @@ class PaiementFourn extends Paiement // Verifier si paiement ne porte pas sur ecriture bancaire rapprochee // Si c'est le cas, on refuse le delete - if ($bank_line_id) - { + if ($bank_line_id) { $accline = new AccountLine($this->db); $accline->fetch($bank_line_id); - if ($accline->rappro) - { + if ($accline->rappro) { $this->error = "ErrorCantDeletePaymentReconciliated"; $this->db->rollback(); return -3; @@ -353,41 +341,34 @@ class PaiementFourn extends Paiement $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn'; $sql .= ' WHERE fk_paiementfourn = '.$this->id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'paiementfourn'; $sql .= ' WHERE rowid = '.$this->id; $result = $this->db->query($sql); - if (!$result) - { + if (!$result) { $this->error = $this->db->error(); $this->db->rollback(); return -3; } // Supprimer l'ecriture bancaire si paiement lie a ecriture - if ($bank_line_id) - { + if ($bank_line_id) { $accline = new AccountLine($this->db); $result = $accline->fetch($bank_line_id); - if ($result > 0) // If result = 0, record not found, we don't try to delete - { + if ($result > 0) { // If result = 0, record not found, we don't try to delete $result = $accline->delete($user); } - if ($result < 0) - { + if ($result < 0) { $this->error = $accline->error; $this->db->rollback(); return -4; } } - if (!$notrigger) - { + if (!$notrigger) { // Appel des triggers $result = $this->call_trigger('PAYMENT_SUPPLIER_DELETE', $user); - if ($result < 0) - { + if ($result < 0) { $this->db->rollback(); return -1; } @@ -416,22 +397,18 @@ class PaiementFourn extends Paiement $sql .= ' WHERE c.rowid = '.$id; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $num = $this->db->num_rows($resql); - if ($num) - { + if ($num) { $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; - if ($obj->fk_user_creat) - { + if ($obj->fk_user_creat) { $cuser = new User($this->db); $cuser->fetch($obj->fk_user_creat); $this->user_creation = $cuser; } - if ($obj->fk_user_modif) - { + if ($obj->fk_user_modif) { $muser = new User($this->db); $muser->fetch($obj->fk_user_modif); $this->user_modification = $muser; @@ -456,18 +433,18 @@ class PaiementFourn extends Paiement $sql = 'SELECT fk_facturefourn'; $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql .= ' WHERE pf.fk_facturefourn = f.rowid AND fk_paiementfourn = '.$this->id; - if ($filter) $sql .= ' AND '.$filter; + if ($filter) { + $sql .= ' AND '.$filter; + } dol_syslog(get_class($this).'::getBillsArray', LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $i = 0; $num = $this->db->num_rows($resql); $billsarray = array(); - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); $billsarray[$i] = $obj->fk_facturefourn; $i++; @@ -564,20 +541,28 @@ class PaiementFourn extends Paiement $reg = array(); if (preg_match('/^\((.*)\)$/i', $text, $reg)) { // Label generique car entre parentheses. On l'affiche en le traduisant - if ($reg[1] == 'paiement') $reg[1] = 'Payment'; + if ($reg[1] == 'paiement') { + $reg[1] = 'Payment'; + } $text = $langs->trans($reg[1]); } $label = ''.$langs->trans("Payment").'
'; $label .= ''.$langs->trans("Ref").': '.$text; - if ($this->datepaye ? $this->datepaye : $this->date) $label .= '
'.$langs->trans("Date").': '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour'); + if ($this->datepaye ? $this->datepaye : $this->date) { + $label .= '
'.$langs->trans("Date").': '.dol_print_date($this->datepaye ? $this->datepaye : $this->date, 'dayhour'); + } $linkstart = '
'; $linkend = ''; $result .= $linkstart; - if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); - if ($withpicto != 2) $result .= $this->ref; + if ($withpicto) { + $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); + } + if ($withpicto != 2) { + $result .= $this->ref; + } $result .= $linkend; return $result; @@ -622,12 +607,15 @@ class PaiementFourn extends Paiement $langs->load("bills"); // Clean parameters (if not defined or using deprecated value) - if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan'; - elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'brodator') $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator'; - elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'bronan') $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan'; + if (empty($conf->global->SUPPLIER_PAYMENT_ADDON)) { + $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan'; + } elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'brodator') { + $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_brodator'; + } elseif ($conf->global->SUPPLIER_PAYMENT_ADDON == 'bronan') { + $conf->global->SUPPLIER_PAYMENT_ADDON = 'mod_supplier_payment_bronan'; + } - if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON)) - { + if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON)) { $mybool = false; $file = $conf->global->SUPPLIER_PAYMENT_ADDON.".php"; @@ -640,8 +628,7 @@ class PaiementFourn extends Paiement $dir = dol_buildpath($reldir."core/modules/supplier_payment/"); // Load file with numbering class (if found) - if (is_file($dir.$file) && is_readable($dir.$file)) - { + if (is_file($dir.$file) && is_readable($dir.$file)) { $mybool |= include_once $dir.$file; } } @@ -706,18 +693,15 @@ class PaiementFourn extends Paiement $langs->load("suppliers"); // Set the model on the model name to use - if (empty($modele)) - { - if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)) - { + if (empty($modele)) { + if (!empty($conf->global->SUPPLIER_PAYMENT_ADDON_PDF)) { $modele = $conf->global->SUPPLIER_PAYMENT_ADDON_PDF; } else { $modele = ''; // No default value. For supplier invoice, we allow to disable all PDF generation } } - if (empty($modele)) - { + if (empty($modele)) { return 0; } else { $modelpath = "core/modules/supplier_payment/doc/"; @@ -738,12 +722,9 @@ class PaiementFourn extends Paiement global $conf; $way = 'dolibarr'; - if (!empty($conf->multicurrency->enabled)) - { - foreach ($this->multicurrency_amounts as $value) - { - if (!empty($value)) // one value found then payment is in invoice currency - { + if (!empty($conf->multicurrency->enabled)) { + foreach ($this->multicurrency_amounts as $value) { + if (!empty($value)) { // one value found then payment is in invoice currency $way = 'customer'; break; } @@ -766,14 +747,11 @@ class PaiementFourn extends Paiement // phpcs:enable require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; - if (empty($force_thirdparty_id)) - { + if (empty($force_thirdparty_id)) { $billsarray = $this->getBillsArray(); // From payment, the fk_soc isn't available, we should load the first supplier invoice to get him - if (!empty($billsarray)) - { + if (!empty($billsarray)) { $supplier_invoice = new FactureFournisseur($this->db); - if ($supplier_invoice->fetch($billsarray[0]) > 0) - { + if ($supplier_invoice->fetch($billsarray[0]) > 0) { $force_thirdparty_id = $supplier_invoice->fk_soc; } } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 0aea652de68..76ef5de8af0 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -41,10 +41,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; -if (!empty($conf->supplier_proposal->enabled)) +if (!empty($conf->supplier_proposal->enabled)) { require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php'; -if (!empty($conf->product->enabled)) +} +if (!empty($conf->product->enabled)) { require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +} if (!empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; @@ -56,7 +58,9 @@ if (!empty($conf->variants->enabled)) { } $langs->loadLangs(array('admin', 'orders', 'sendings', 'companies', 'bills', 'propal', 'receptions', 'supplier_proposal', 'deliveries', 'products', 'stocks', 'productbatch')); -if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); +if (!empty($conf->incoterm->enabled)) { + $langs->load('incoterm'); +} $id = GETPOST('id', 'int'); $ref = GETPOST('ref', 'alpha'); @@ -80,7 +84,9 @@ $datelivraison = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int' // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'fournisseur', $id, 'commande_fournisseur', 'commande'); // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context @@ -93,20 +99,26 @@ $extrafields = new ExtraFields($db); $extrafields->fetch_name_optionals_label($object->table_element); // Load object -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $ret = $object->fetch($id, $ref); - if ($ret < 0) dol_print_error($db, $object->error); + if ($ret < 0) { + dol_print_error($db, $object->error); + } $ret = $object->fetch_thirdparty(); - if ($ret < 0) dol_print_error($db, $object->error); -} elseif (!empty($socid) && $socid > 0) -{ + if ($ret < 0) { + dol_print_error($db, $object->error); + } +} elseif (!empty($socid) && $socid > 0) { $fourn = new Fournisseur($db); $ret = $fourn->fetch($socid); - if ($ret < 0) dol_print_error($db, $object->error); + if ($ret < 0) { + dol_print_error($db, $object->error); + } $object->socid = $fourn->id; $ret = $object->fetch_thirdparty(); - if ($ret < 0) dol_print_error($db, $object->error); + if ($ret < 0) { + dol_print_error($db, $object->error); + } } // Common permissions @@ -136,14 +148,13 @@ $permissiontoadd = $usercancreate; // Used by the include of actions_addupdated $parameters = array('socid'=>$socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} -if (empty($reshook)) -{ - if ($cancel) - { - if (!empty($backtopage)) - { +if (empty($reshook)) { + if ($cancel) { + if (!empty($backtopage)) { header("Location: ".$backtopage); exit; } @@ -156,67 +167,69 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once - if ($action == 'setref_supplier' && $usercancreate) - { + if ($action == 'setref_supplier' && $usercancreate) { $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'ORDER_SUPPLIER_MODIFY'); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // Set incoterm - if ($action == 'set_incoterms' && $usercancreate) - { + if ($action == 'set_incoterms' && $usercancreate) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // payment conditions - if ($action == 'setconditions' && $usercancreate) - { + if ($action == 'setconditions' && $usercancreate) { $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // payment mode - if ($action == 'setmode' && $usercancreate) - { + if ($action == 'setmode' && $usercancreate) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); - } - - // Multicurrency Code - elseif ($action == 'setmulticurrencycode' && $usercancreate) { + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } elseif ($action == 'setmulticurrencycode' && $usercancreate) { + // Multicurrency Code $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); - } - - // Multicurrency rate - elseif ($action == 'setmulticurrencyrate' && $usercancreate) { + } elseif ($action == 'setmulticurrencyrate' && $usercancreate) { + // Multicurrency rate $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx'))); } // bank account - if ($action == 'setbankaccount' && $usercancreate) - { + if ($action == 'setbankaccount' && $usercancreate) { $result = $object->setBankAccount(GETPOST('fk_account', 'int')); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // date of delivery - if ($action == 'setdate_livraison' && $usercancreate) - { + if ($action == 'setdate_livraison' && $usercancreate) { $result = $object->setDeliveryDate($user, $datelivraison); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // Set project - if ($action == 'classin' && $usercancreate) - { + if ($action == 'classin' && $usercancreate) { $result = $object->setProject($projectid); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // Edit Thirdparty - if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action == 'set_thirdparty' && $usercancreate && $object->statut == CommandeFournisseur::STATUS_DRAFT) - { + if (!empty($conf->global->MAIN_CAN_EDIT_SUPPLIER_ON_SUPPLIER_ORDER) && $action == 'set_thirdparty' && $usercancreate && $object->statut == CommandeFournisseur::STATUS_DRAFT) { $new_socid = GETPOST('new_socid', 'int'); if (!empty($new_socid) && $new_socid != $object->thirdparty->id) { $db->begin(); @@ -229,8 +242,9 @@ if (empty($reshook)) $res = $db->query($sql); - if (!$res) $db->rollback(); - else { + if (!$res) { + $db->rollback(); + } else { $db->commit(); // Replace prices for each lines by new supplier prices @@ -275,38 +289,44 @@ if (empty($reshook)) exit; } - if ($action == 'setremisepercent' && $usercancreate) - { + if ($action == 'setremisepercent' && $usercancreate) { $result = $object->set_remise($user, $_POST['remise_percent']); - if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } - if ($action == 'reopen') // no test on permission here, permission to use will depends on status - { - if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9))) - { - if ($object->statut == 1) $newstatus = 0; // Validated->Draft - elseif ($object->statut == 2) $newstatus = 0; // Approved->Draft - elseif ($object->statut == 3) $newstatus = 2; // Ordered->Approved - elseif ($object->statut == 4) $newstatus = 3; - elseif ($object->statut == 5) - { + if ($action == 'reopen') { // no test on permission here, permission to use will depends on status + if (in_array($object->statut, array(1, 2, 3, 4, 5, 6, 7, 9))) { + if ($object->statut == 1) { + $newstatus = 0; // Validated->Draft + } elseif ($object->statut == 2) { + $newstatus = 0; // Approved->Draft + } elseif ($object->statut == 3) { + $newstatus = 2; // Ordered->Approved + } elseif ($object->statut == 4) { + $newstatus = 3; + } elseif ($object->statut == 5) { //$newstatus=2; // Ordered // TODO Can we set it to submited ? //$newstatus=3; // Submited // TODO If there is at least one reception, we can set to Received->Received partially $newstatus = 4; // Received partially - } elseif ($object->statut == 6) $newstatus = 2; // Canceled->Approved - elseif ($object->statut == 7) $newstatus = 3; // Canceled->Process running - elseif ($object->statut == 9) $newstatus = 1; // Refused->Validated - else $newstatus = 2; + } elseif ($object->statut == 6) { + $newstatus = 2; // Canceled->Approved + } elseif ($object->statut == 7) { + $newstatus = 3; // Canceled->Process running + } elseif ($object->statut == 9) { + $newstatus = 1; // Refused->Validated + } else { + $newstatus = 2; + } //print "old status = ".$object->statut.' new status = '.$newstatus; $db->begin(); $result = $object->setStatus($user, $newstatus); - if ($result > 0) - { + if ($result > 0) { // Currently the "Re-open" also remove the billed flag because there is no button "Set unpaid" yet. $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; $sql .= ' SET billed = 0'; @@ -314,8 +334,7 @@ if (empty($reshook)) $resql = $db->query($sql); - if ($newstatus == 0) - { + if ($newstatus == 0) { $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur'; $sql .= ' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null'; $sql .= ' WHERE rowid = '.$object->id; @@ -338,8 +357,7 @@ if (empty($reshook)) /* * Classify supplier order as billed */ - if ($action == 'classifybilled' && $usercancreate) - { + if ($action == 'classifybilled' && $usercancreate) { $ret = $object->classifyBilled($user); if ($ret < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -347,8 +365,7 @@ if (empty($reshook)) } // Add a product line - if ($action == 'addline' && $usercancreate) - { + if ($action == 'addline' && $usercancreate) { $db->begin(); $langs->load('errors'); @@ -360,8 +377,7 @@ if (empty($reshook)) $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $prod_entry_mode = GETPOST('prod_entry_mode'); - if ($prod_entry_mode == 'free') - { + if ($prod_entry_mode == 'free') { $idprod = 0; $price_ht = price2num(GETPOST('price_ht'), 'MU'); $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); @@ -386,28 +402,23 @@ if (empty($reshook)) } } - if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) - { + if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) { setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors'); $error++; } - if ($prod_entry_mode == 'free' && !GETPOST('idprodfournprice') && GETPOST('type') < 0) - { + if ($prod_entry_mode == 'free' && !GETPOST('idprodfournprice') && GETPOST('type') < 0) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); $error++; } - if ($prod_entry_mode == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') // Unit price can be 0 but not '' - { + if ($prod_entry_mode == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') { // Unit price can be 0 but not '' setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice')), null, 'errors'); $error++; } - if ($prod_entry_mode == 'free' && !GETPOST('dp_desc')) - { + if ($prod_entry_mode == 'free' && !GETPOST('dp_desc')) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors'); $error++; } - if (GETPOST('qty', 'int') == '') - { + if (GETPOST('qty', 'int') == '') { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); $error++; } @@ -426,51 +437,49 @@ if (empty($reshook)) } } - if ($prod_entry_mode != 'free' && empty($error)) // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or '' - { + if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or '' $productsupplier = new ProductFournisseur($db); $idprod = 0; - if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...) + if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') { + $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...) + } $reg = array(); - if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) - { + if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) { $idprod = $reg[1]; $res = $productsupplier->fetch($idprod); // Load product from its id // Call to init some price properties of $productsupplier // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price - if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) - { + if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) { $fksoctosearch = 0; $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist - if ($productsupplier->fourn_socid != $socid) // The price we found is for another supplier, so we clear supplier price - { + if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price $productsupplier->ref_supplier = ''; } } else { $fksoctosearch = $object->thirdparty->id; $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist } - } elseif (GETPOST('idprodfournprice', 'alpha') > 0) - { + } elseif (GETPOST('idprodfournprice', 'alpha') > 0) { $qtytosearch = $qty; // Just to see if a price exists for the quantity. Not used to found vat. //$qtytosearch=-1; // We force qty to -1 to be sure to find if a supplier price exist $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch); $res = $productsupplier->fetch($idprod); } - if ($idprod > 0) - { + if ($idprod > 0) { $label = $productsupplier->label; // Define output language if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id', 'aZ09')) + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); - if (empty($newlang)) + } + if (empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -489,8 +498,12 @@ if (empty($reshook)) $product_desc=''; } - if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) $desc = $product_desc; - if (!empty($product_desc) && trim($product_desc) != trim($desc)) $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); + if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) { + $desc = $product_desc; + } + if (!empty($product_desc) && trim($product_desc) != trim($desc)) { + $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION)); + } $type = $productsupplier->type; if ($price_ht != '' || $price_ht_devise != '') { @@ -514,11 +527,15 @@ if (empty($reshook)) $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha')); $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha')); - if (empty($tva_tx)) $tva_npr = 0; + if (empty($tva_tx)) { + $tva_npr = 0; + } $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr); - if (empty($pu)) $pu = 0; // If pu is '' or null, we force to have a numeric value + if (empty($pu)) { + $pu = 0; // If pu is '' or null, we force to have a numeric value + } $result = $object->addline( $desc, @@ -545,22 +562,19 @@ if (empty($reshook)) 0 ); } - if ($idprod == -99 || $idprod == 0) - { + if ($idprod == -99 || $idprod == 0) { // Product not selected $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors'); } - if ($idprod == -1) - { + if ($idprod == -1) { // Quantity too low $error++; $langs->load("errors"); setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors'); } - } elseif (empty($error)) // $price_ht is already set - { + } elseif (empty($error)) { // $price_ht is already set $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0); $tva_tx = str_replace('*', '', $tva_tx); $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); @@ -578,8 +592,7 @@ if (empty($reshook)) $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty); $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty); - if ($price_ht !== '') - { + if ($price_ht !== '') { $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings } else { $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); @@ -592,19 +605,21 @@ if (empty($reshook)) } //print "xx".$tva_tx; exit; - if (!$error && $result > 0) - { + if (!$error && $result > 0) { $db->commit(); $ret = $object->fetch($object->id); // Reload to get new records // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -613,7 +628,9 @@ if (empty($reshook)) $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) dol_print_error($db, $result); + if ($result < 0) { + dol_print_error($db, $result); + } } unset($_POST ['prod_entry_mode']); @@ -658,17 +675,17 @@ if (empty($reshook)) /* * Updating a line in the order */ - if ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) - { + if ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) { $db->begin(); $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); - if ($lineid) - { + if ($lineid) { $line = new CommandeFournisseurLigne($db); $res = $line->fetch($lineid); - if (!$res) dol_print_error($db); + if (!$res) { + dol_print_error($db); + } } $productsupplier = new ProductFournisseur($db); @@ -692,14 +709,12 @@ if (empty($reshook)) $localtax1_rate = get_localtax($vat_rate, 1, $mysoc, $object->thirdparty); $localtax2_rate = get_localtax($vat_rate, 2, $mysoc, $object->thirdparty); - if (GETPOST('price_ht') != '') - { + if (GETPOST('price_ht') != '') { $price_base_type = 'HT'; $ht = price2num(GETPOST('price_ht')); } else { $vatratecleaned = $vat_rate; - if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) // If vat is "xx (yy)" - { + if (preg_match('/^(.*)\s*\((.*)\)$/', $vat_rate, $reg)) { // If vat is "xx (yy)" $vatratecleaned = trim($reg[1]); $vatratecode = $reg[2]; } @@ -769,15 +784,17 @@ if (empty($reshook)) unset($_POST['date_endmonth']); unset($_POST['date_endyear']); - if ($result >= 0) - { + if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -786,7 +803,9 @@ if (empty($reshook)) $ret = $object->fetch($id); // Reload to get new records $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result < 0) dol_print_error($db, $result); + if ($result < 0) { + dol_print_error($db, $result); + } } $db->commit(); @@ -799,20 +818,20 @@ if (empty($reshook)) } // Remove a product line - if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) - { + if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { $db->begin(); $result = $object->deleteline($lineid); - if ($result > 0) - { + if ($result > 0) { // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -839,21 +858,22 @@ if (empty($reshook)) } // Validate - if ($action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate) - { + if ($action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate) { $db->begin(); $object->date_commande = dol_now(); $result = $object->valid($user); - if ($result >= 0) - { + if ($result >= 0) { // Define output language - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -873,8 +893,7 @@ if (empty($reshook)) } // If we have permission, and if we don't need to provide the idwarehouse, we go directly on approved step - if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))) - { + if (!$error && empty($conf->global->SUPPLIER_ORDER_NO_DIRECT_APPROVE) && $usercanapprove && !(!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))) { $action = 'confirm_approve'; // can make standard or first level approval also if permission is set } @@ -885,41 +904,39 @@ if (empty($reshook)) } } - if (($action == 'confirm_approve' || $action == 'confirm_approve2') && $confirm == 'yes' && $usercanapprove) - { + if (($action == 'confirm_approve' || $action == 'confirm_approve2') && $confirm == 'yes' && $usercanapprove) { $db->begin(); $idwarehouse = GETPOST('idwarehouse', 'int'); $qualified_for_stock_change = 0; - if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { - $qualified_for_stock_change = $object->hasProductsOrServices(2); + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + $qualified_for_stock_change = $object->hasProductsOrServices(2); } else { - $qualified_for_stock_change = $object->hasProductsOrServices(1); + $qualified_for_stock_change = $object->hasProductsOrServices(1); } // Check parameters - if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) // warning name of option should be STOCK_CALCULATE_ON_SUPPLIER_APPROVE_ORDER - { - if (!$idwarehouse || $idwarehouse == -1) - { + if (!empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $qualified_for_stock_change) { // warning name of option should be STOCK_CALCULATE_ON_SUPPLIER_APPROVE_ORDER + if (!$idwarehouse || $idwarehouse == -1) { $error++; setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $action = ''; } } - if (!$error) - { + if (!$error) { $result = $object->approve($user, $idwarehouse, ($action == 'confirm_approve2' ? 1 : 0)); - if ($result > 0) - { + if ($result > 0) { if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -942,11 +959,9 @@ if (empty($reshook)) } } - if ($action == 'confirm_refuse' && $confirm == 'yes' && $usercanapprove) - { + if ($action == 'confirm_refuse' && $confirm == 'yes' && $usercanapprove) { $result = $object->refuse($user); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { @@ -964,19 +979,20 @@ if (empty($reshook)) } } - if ($action == 'confirm_commande' && $confirm == 'yes' && $usercanorder) - { + if ($action == 'confirm_commande' && $confirm == 'yes' && $usercanorder) { $db->begin(); $result = $object->commande($user, GETPOST("datecommande"), GETPOST("methode", 'int'), GETPOST('comment', 'alphanohtml')); - if ($result > 0) - { - if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) - { + if ($result > 0) { + if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); @@ -1000,11 +1016,9 @@ if (empty($reshook)) } - if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) - { + if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) { $result = $object->delete($user); - if ($result > 0) - { + if ($result > 0) { header("Location: ".DOL_URL_ROOT.'/fourn/commande/list.php?restore_lastsearch_values=1'); exit; } else { @@ -1013,19 +1027,15 @@ if (empty($reshook)) } // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) - { - if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) - { + if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) { + if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) { setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors'); } else { - if ($object->id > 0) - { + if ($object->id > 0) { $orig = clone $object; $result = $object->createFromClone($user, $socid); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result); exit; } else { @@ -1038,22 +1048,18 @@ if (empty($reshook)) } // Set status of reception (complete, partial, ...) - if ($action == 'livraison' && $usercanreceived) - { + if ($action == 'livraison' && $usercanreceived) { $db->begin(); - if (GETPOST("type") != '') - { + if (GETPOST("type") != '') { $date_liv = dol_mktime(GETPOST('rehour'), GETPOST('remin'), GETPOST('resec'), GETPOST("remonth"), GETPOST("reday"), GETPOST("reyear")); $result = $object->Livraison($user, $date_liv, GETPOST("type"), GETPOST("comment")); // GETPOST("type") is 'tot', 'par', 'nev', 'can' - if ($result > 0) - { + if ($result > 0) { $langs->load("deliveries"); setEventMessages($langs->trans("DeliveryStateSaved"), null); $action = ''; - } elseif ($result == -3) - { + } elseif ($result == -3) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } else { @@ -1072,11 +1078,9 @@ if (empty($reshook)) } } - if ($action == 'confirm_cancel' && $confirm == 'yes' && $usercanorder) - { + if ($action == 'confirm_cancel' && $confirm == 'yes' && $usercanorder) { $result = $object->cancel($user); - if ($result > 0) - { + if ($result > 0) { header("Location: ".$_SERVER["PHP_SELF"]."?id=".$object->id); exit; } else { @@ -1099,48 +1103,44 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; - if ($action == 'update_extras') - { + if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } - if (!$error) - { + if (!$error) { // Actions on extra fields - if (!$error) - { + if (!$error) { $result = $object->insertExtraFields('ORDER_SUPPLIER_MODIFY'); - if ($result < 0) - { + if ($result < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } } } - if ($error) + if ($error) { $action = 'edit_extras'; + } } /* * Create an order */ - if ($action == 'add' && $usercancreate) - { - $error = 0; + if ($action == 'add' && $usercancreate) { + $error = 0; $selectedLines = GETPOST('toselect', 'array'); - if ($socid < 1) - { + if ($socid < 1) { setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors'); $action = 'create'; $error++; } - if (!$error) - { + if (!$error) { $db->begin(); // Creation commande @@ -1160,23 +1160,20 @@ if (empty($reshook)) $object->fk_project = GETPOST('projectid'); // Fill array 'array_options' with data from add form - if (!$error) - { + if (!$error) { $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; - } + if ($ret < 0) { + $error++; + } + } - if (!$error) - { - // If creation from another object of another module (Example: origin=propal, originid=1) - if (!empty($origin) && !empty($originid)) - { - if ($origin == 'propal' || $origin == 'proposal') - { + if (!$error) { + // If creation from another object of another module (Example: origin=propal, originid=1) + if (!empty($origin) && !empty($originid)) { + if ($origin == 'propal' || $origin == 'proposal') { $classname = 'Propal'; $element = 'comm/propal'; $subelement = 'propal'; - } elseif ($origin == 'order' || $origin == 'commande') - { + } elseif ($origin == 'order' || $origin == 'commande') { $classname = 'Commande'; $element = $subelement = 'commande'; } else { @@ -1196,23 +1193,20 @@ if (empty($reshook)) } $id = $object->create($user); - if ($id > 0) - { + if ($id > 0) { dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); $srcobject = new $classname($db); dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); $result = $srcobject->fetch($object->origin_id); - if ($result > 0) - { + if ($result > 0) { $tmpdate = ($srcobject->delivery_date ? $srcobject->delivery_date : $srcobject->date_livraison); $object->setDeliveryDate($user, $tmpdate); $object->set_id_projet($user, $srcobject->fk_project); $lines = $srcobject->lines; - if (empty($lines) && method_exists($srcobject, 'fetch_lines')) - { + if (empty($lines) && method_exists($srcobject, 'fetch_lines')) { $srcobject->fetch_lines(); $lines = $srcobject->lines; } @@ -1220,10 +1214,10 @@ if (empty($reshook)) $fk_parent_line = 0; $num = count($lines); - for ($i = 0; $i < $num; $i++) - { - if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->id, $selectedLines)) + for ($i = 0; $i < $num; $i++) { + if (empty($lines[$i]->subprice) || $lines[$i]->qty <= 0 || !in_array($lines[$i]->id, $selectedLines)) { continue; + } $label = (!empty($lines[$i]->label) ? $lines[$i]->label : ''); $desc = (!empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->product_desc); @@ -1235,20 +1229,17 @@ if (empty($reshook)) } // Extrafields - if (method_exists($lines[$i], 'fetch_optionals')) // For avoid conflicts if - { + if (method_exists($lines[$i], 'fetch_optionals')) { // For avoid conflicts if $lines[$i]->fetch_optionals(); $array_option = $lines[$i]->array_options; } $ref_supplier = ''; $product_fourn_price_id = 0; - if ($origin == "commande") - { + if ($origin == "commande") { $productsupplier = new ProductFournisseur($db); $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty, $srcobject->socid); - if ($result > 0) - { + if ($result > 0) { $ref_supplier = $productsupplier->ref_supplier; $product_fourn_price_id = $productsupplier->product_fourn_price_id; } @@ -1259,8 +1250,7 @@ if (empty($reshook)) $tva_tx = $lines[$i]->tva_tx; - if ($origin == "commande") - { + if ($origin == "commande") { $soc = new societe($db); $soc->fetch($socid); $tva_tx = get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $product_fourn_price_id); @@ -1309,8 +1299,9 @@ if (empty($reshook)) $parameters = array('objFrom' => $srcobject); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been - if ($reshook < 0) + if ($reshook < 0) { $error++; + } } else { setEventMessages($srcobject->error, $srcobject->errors, 'errors'); $error++; @@ -1320,17 +1311,15 @@ if (empty($reshook)) $error++; } } else { - $id = $object->create($user); - if ($id < 0) - { + $id = $object->create($user); + if ($id < 0) { $error++; setEventMessages($object->error, $object->errors, 'errors'); } } } - if ($error) - { + if ($error) { $langs->load("errors"); $db->rollback(); $action = 'create'; @@ -1343,8 +1332,7 @@ if (empty($reshook)) } } - if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && !GETPOST('cancel', 'alpha')) - { + if ($action == 'webservice' && GETPOST('mode', 'alpha') == "send" && !GETPOST('cancel', 'alpha')) { $ws_url = $object->thirdparty->webservices_url; $ws_key = $object->thirdparty->webservices_key; $ws_user = GETPOST('ws_user', 'alpha'); @@ -1382,13 +1370,11 @@ if (empty($reshook)) //Prepare the order lines from order $order_lines = array(); - foreach ($object->lines as $line) - { + foreach ($object->lines as $line) { $ws_parameters = array('authentication' => $ws_authentication, 'id' => '', 'ref' => $line->ref_supplier); $result_product = $soapclient_product->call("getProductOrService", $ws_parameters, $ws_ns, ''); - if ($result_product["result"]["result_code"] == "OK") - { + if ($result_product["result"]["result_code"] == "OK") { $order_lines[] = array( 'desc' => $line->product_desc, 'type' => $line->product_type, @@ -1419,11 +1405,9 @@ if (empty($reshook)) $ws_parameters = array('authentication'=>$ws_authentication, 'order' => $order); $result_order = $soapclient_order->call("createOrder", $ws_parameters, $ws_ns, ''); - if (empty($result_order["result"]["result_code"])) //No result, check error str - { + if (empty($result_order["result"]["result_code"])) { //No result, check error str setEventMessages($langs->trans("SOAPError")." '".$soapclient_order->error_str."'", null, 'errors'); - } elseif ($result_order["result"]["result_code"] != "OK") //Something went wrong - { + } elseif ($result_order["result"]["result_code"] != "OK") { //Something went wrong setEventMessages($langs->trans("SOAPError")." '".$result_order["result"]["result_code"]."' - '".$result_order["result"]["result_label"]."'", null, 'errors'); } else { setEventMessages($langs->trans("RemoteOrderRef")." ".$result_order["ref"], null, 'mesgs'); @@ -1431,45 +1415,33 @@ if (empty($reshook)) } } - if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) - { - if ($action == 'addcontact') - { - if ($object->id > 0) - { + if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) { + if ($action == 'addcontact') { + if ($object->id > 0) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); } - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors'); } else { setEventMessages($object->error, $object->errors, 'errors'); } } - } - - // bascule du statut d'un contact - elseif ($action == 'swapstatut' && $object->id > 0) - { + } elseif ($action == 'swapstatut' && $object->id > 0) { + // bascule du statut d'un contact $result = $object->swapContactStatus(GETPOST('ligne')); - } - - // Efface un contact - elseif ($action == 'deletecontact' && $object->id > 0) - { + } elseif ($action == 'deletecontact' && $object->id > 0) { + // Efface un contact $result = $object->delete_contact($_GET["lineid"]); - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { @@ -1488,15 +1460,16 @@ $form = new Form($db); $formfile = new FormFile($db); $formorder = new FormOrder($db); $productstatic = new Product($db); -if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} $help_url = 'EN:Module_Suppliers_Orders|FR:CommandeFournisseur|ES:Módulo_Pedidos_a_proveedores'; llxHeader('', $langs->trans("Order"), $help_url); $now = dol_now(); -if ($action == 'create') -{ +if ($action == 'create') { print load_fiche_titre($langs->trans('NewOrderSupplier'), '', 'supplier_order'); dol_htmloutput_events(); @@ -1504,14 +1477,12 @@ if ($action == 'create') $currency_code = $conf->currency; $societe = ''; - if ($socid > 0) - { + if ($socid > 0) { $societe = new Societe($db); $societe->fetch($socid); } - if (!empty($origin) && !empty($originid)) - { + if (!empty($origin) && !empty($originid)) { // Parse element/subelement (ex: project_task) $element = $subelement = $origin; $regs = array(); @@ -1520,12 +1491,10 @@ if ($action == 'create') $subelement = $regs[2]; } - if ($origin == 'propal' || $origin == 'proposal') - { + if ($origin == 'propal' || $origin == 'proposal') { $classname = 'Propal'; $element = 'comm/propal'; $subelement = 'propal'; - } elseif ($origin == 'order' || $origin == 'commande') - { + } elseif ($origin == 'order' || $origin == 'commande') { $classname = 'Commande'; $element = $subelement = 'commande'; } else { @@ -1538,8 +1507,9 @@ if ($action == 'create') $objectsrc = new $classname($db); $objectsrc->fetch($originid); - if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) + if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) { $objectsrc->fetch_lines(); + } $objectsrc->fetch_thirdparty(); // Replicate extrafields @@ -1562,10 +1532,13 @@ if ($action == 'create') $datedelivery = (!empty($objectsrc->date_livraison) ? $objectsrc->date_livraison : (!empty($objectsrc->delivery_date) ? $objectsrc->delivery_date : '')); - if (!empty($conf->multicurrency->enabled)) - { - if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code; - if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx; + if (!empty($conf->multicurrency->enabled)) { + if (!empty($objectsrc->multicurrency_code)) { + $currency_code = $objectsrc->multicurrency_code; + } + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) { + $currency_tx = $objectsrc->multicurrency_tx; + } } $note_private = $object->getDefaultCreateValueFor('note_private', (!empty($objectsrc->note_private) ? $objectsrc->note_private : null)); @@ -1577,15 +1550,21 @@ if ($action == 'create') $cond_reglement_id = $societe->cond_reglement_supplier_id; $mode_reglement_id = $societe->mode_reglement_supplier_id; - if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) $currency_code = $societe->multicurrency_code; + if (!empty($conf->multicurrency->enabled) && !empty($societe->multicurrency_code)) { + $currency_code = $societe->multicurrency_code; + } $note_private = $object->getDefaultCreateValueFor('note_private'); $note_public = $object->getDefaultCreateValueFor('note_public'); } // If not defined, set default value from constant - if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID; - if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID; + if (empty($cond_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID)) { + $cond_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_TERM_ID; + } + if (empty($mode_reglement_id) && !empty($conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID)) { + $mode_reglement_id = $conf->global->SUPPLIER_ORDER_DEFAULT_PAYMENT_MODE_ID; + } print '
'; print ''; @@ -1594,7 +1573,9 @@ if ($action == 'create') print ''; print ''; print ''; - if (!empty($currency_tx)) print ''; + if (!empty($currency_tx)) { + print ''; + } print dol_get_fiche_head(''); @@ -1607,15 +1588,13 @@ if ($action == 'create') print ''.$langs->trans('Supplier').''; print ''; - if ($socid > 0) - { + if ($socid > 0) { print $societe->getNomUrl(1); print ''; } else { print img_picto('', 'company').$form->select_company((empty($socid) ? '' : $socid), 'socid', 's.fournisseur=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); // reload page to retrieve customer informations - if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) - { + if (!empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE)) { print '