From 8db4291f88c9d2a149b67e9ea2ec1b33bfb9ee49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 25 Feb 2021 22:38:35 +0100 Subject: [PATCH] code syntax expedition directory --- htdocs/expedition/card.php | 1068 ++++++++--------- .../expedition/class/api_shipments.class.php | 368 +++--- htdocs/expedition/class/expedition.class.php | 832 ++++++------- .../class/expeditionbatch.class.php | 31 +- .../class/expeditionstats.class.php | 23 +- htdocs/expedition/contact.php | 61 +- htdocs/expedition/document.php | 18 +- htdocs/expedition/index.php | 76 +- htdocs/expedition/list.php | 575 +++++---- htdocs/expedition/note.php | 19 +- htdocs/expedition/shipment.php | 292 +++-- htdocs/expedition/stats/index.php | 140 +-- .../expedition/tpl/linkedobjectblock.tpl.php | 56 +- 13 files changed, 1773 insertions(+), 1786 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 0652424d919..1b723cf716d 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -46,9 +46,15 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; +if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +} +if (!empty($conf->propal->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +} +if (!empty($conf->productbatch->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.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'; @@ -57,25 +63,38 @@ if (!empty($conf->projet->enabled)) { // Load translation files required by the page $langs->loadLangs(array("sendings", "companies", "bills", 'deliveries', 'orders', 'stocks', 'other', 'propal')); -if (!empty($conf->incoterm->enabled)) $langs->load('incoterm'); -if (!empty($conf->productbatch->enabled)) $langs->load('productbatch'); +if (!empty($conf->incoterm->enabled)) { + $langs->load('incoterm'); +} +if (!empty($conf->productbatch->enabled)) { + $langs->load('productbatch'); +} $origin = GETPOST('origin', 'alpha') ?GETPOST('origin', 'alpha') : 'expedition'; // Example: commande, propal $origin_id = GETPOST('id', 'int') ?GETPOST('id', 'int') : ''; $id = $origin_id; -if (empty($origin_id)) $origin_id = GETPOST('origin_id', 'int'); // Id of order or propal -if (empty($origin_id)) $origin_id = GETPOST('object_id', 'int'); // Id of order or propal +if (empty($origin_id)) { + $origin_id = GETPOST('origin_id', 'int'); // Id of order or propal +} +if (empty($origin_id)) { + $origin_id = GETPOST('object_id', 'int'); // Id of order or propal +} $ref = GETPOST('ref', 'alpha'); $line_id = GETPOST('lineid', 'int') ?GETPOST('lineid', 'int') : ''; // Security check $socid = ''; -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} -if ($origin == 'expedition') $result = restrictedArea($user, $origin, $id); -else { +if ($origin == 'expedition') { + $result = restrictedArea($user, $origin, $id); +} else { $result = restrictedArea($user, 'expedition'); - if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) accessforbidden(); + if (empty($user->rights->{$origin}->lire) && empty($user->rights->{$origin}->read)) { + accessforbidden(); + } } $action = GETPOST('action', 'alpha'); @@ -114,12 +133,12 @@ $date_delivery = dol_mktime(GETPOST('date_deliveryhour', 'int'), GETPOST('date_d $parameters = array(); $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($reshook)) { + if ($cancel) { $action = ''; $object->fetch($id); // show shipment also after canceling modification } @@ -132,20 +151,17 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; // Reopen - if ($action == 'reopen' && $user->rights->expedition->creer) - { + if ($action == 'reopen' && $user->rights->expedition->creer) { $object->fetch($id); $result = $object->reOpen(); } // Set incoterm - if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) - { + if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); } - if ($action == 'setref_customer') - { + if ($action == 'setref_customer') { $result = $object->fetch($id); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -161,32 +177,31 @@ if (empty($reshook)) } } - if ($action == 'update_extras') - { + if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update 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 $result = $object->insertExtraFields('SHIPMENT_MODIFY'); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } - if ($error) + if ($error) { $action = 'edit_extras'; + } } // Create shipment - if ($action == 'add' && $user->rights->expedition->creer) - { + if ($action == 'add' && $user->rights->expedition->creer) { $error = 0; $db->begin(); @@ -226,8 +241,7 @@ if (empty($reshook)) $num = count($objectsrc->lines); $totalqty = 0; - for ($i = 0; $i < $num; $i++) - { + for ($i = 0; $i < $num; $i++) { $idl = "idl".$i; $sub_qty = array(); @@ -238,14 +252,11 @@ if (empty($reshook)) $stockLocation = "ent1".$i."_0"; $qty = "qtyl".$i; - if (!empty($conf->productbatch->enabled) && $objectsrc->lines[$i]->product_tobatch) // If product need a batch number - { - if (GETPOSTISSET($batch)) - { + if (!empty($conf->productbatch->enabled) && $objectsrc->lines[$i]->product_tobatch) { // If product need a batch number + if (GETPOSTISSET($batch)) { //shipment line with batch-enable product $qty .= '_'.$j; - while (GETPOSTISSET($batch)) - { + while (GETPOSTISSET($batch)) { // save line of detail into sub_qty $sub_qty[$j]['q'] = GETPOST($qty, 'int'); // the qty we want to move for this stock record $sub_qty[$j]['id_batch'] = GETPOST($batch, 'int'); // the id into llx_product_batch of stock record to move @@ -265,8 +276,7 @@ if (empty($reshook)) $totalqty += $subtotalqty; } else { // No detail were provided for lots - if (!empty($_POST[$qty])) - { + if (!empty($_POST[$qty])) { // We try to set an amount // Case we dont use the list of available qty for each warehouse/lot // GUI does not allow this yet @@ -276,8 +286,7 @@ if (empty($reshook)) } elseif (GETPOSTISSET($stockLocation)) { //shipment line from multiple stock locations $qty .= '_'.$j; - while (GETPOSTISSET($stockLocation)) - { + while (GETPOSTISSET($stockLocation)) { // save sub line of warehouse $stockLine[$i][$j]['qty'] = price2num(GETPOST($qty, 'alpha'), 'MS'); $stockLine[$i][$j]['warehouse_id'] = GETPOST($stockLocation, 'int'); @@ -292,7 +301,9 @@ if (empty($reshook)) } else { //var_dump(GETPOST($qty,'alpha')); var_dump($_POST); var_dump($batch);exit; //shipment line for product with no batch management and no multiple stock location - if (GETPOST($qty, 'int') > 0) $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS'); + if (GETPOST($qty, 'int') > 0) { + $totalqty += price2num(GETPOST($qty, 'alpha'), 'MS'); + } } // Extrafields @@ -308,43 +319,38 @@ if (empty($reshook)) //var_dump($batch_line[2]); - if ($totalqty > 0) // There is at least one thing to ship - { + if ($totalqty > 0) { // There is at least one thing to ship //var_dump($_POST);exit; - for ($i = 0; $i < $num; $i++) - { + for ($i = 0; $i < $num; $i++) { $qty = "qtyl".$i; - if (!isset($batch_line[$i])) - { + if (!isset($batch_line[$i])) { // not batch mode - if (isset($stockLine[$i])) - { + if (isset($stockLine[$i])) { //shipment from multiple stock locations $nbstockline = count($stockLine[$i]); - for ($j = 0; $j < $nbstockline; $j++) - { - if ($stockLine[$i][$j]['qty'] > 0) - { + for ($j = 0; $j < $nbstockline; $j++) { + if ($stockLine[$i][$j]['qty'] > 0) { $ret = $object->addline($stockLine[$i][$j]['warehouse_id'], $stockLine[$i][$j]['ix_l'], $stockLine[$i][$j]['qty'], $array_options[$i]); - if ($ret < 0) - { + if ($ret < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } } } else { - if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS)) - { + if (GETPOST($qty, 'int') > 0 || (GETPOST($qty, 'int') == 0 && $conf->global->SHIPMENT_GETS_ALL_ORDER_PRODUCTS)) { $ent = "entl".$i; $idl = "idl".$i; $entrepot_id = is_numeric(GETPOST($ent, 'int')) ?GETPOST($ent, 'int') : GETPOST('entrepot_id', 'int'); - if ($entrepot_id < 0) $entrepot_id = ''; - if (!($objectsrc->lines[$i]->fk_product > 0)) $entrepot_id = 0; + if ($entrepot_id < 0) { + $entrepot_id = ''; + } + if (!($objectsrc->lines[$i]->fk_product > 0)) { + $entrepot_id = 0; + } $ret = $object->addline($entrepot_id, GETPOST($idl, 'int'), GETPOST($qty, 'int'), $array_options[$i]); - if ($ret < 0) - { + if ($ret < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } @@ -352,11 +358,9 @@ if (empty($reshook)) } } else { // batch mode - if ($batch_line[$i]['qty'] > 0) - { + if ($batch_line[$i]['qty'] > 0) { $ret = $object->addline_batch($batch_line[$i], $array_options[$i]); - if ($ret < 0) - { + if ($ret < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } @@ -365,13 +369,13 @@ if (empty($reshook)) } // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost(null, $object); - if ($ret < 0) $error++; + if ($ret < 0) { + $error++; + } - if (!$error) - { + if (!$error) { $ret = $object->create($user); // This create shipment (like Odoo picking) and lines of shipments. Stock movement will be done when validating shipment. - if ($ret <= 0) - { + if ($ret <= 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } @@ -381,8 +385,7 @@ if (empty($reshook)) $error++; } - if (!$error) - { + if (!$error) { $db->commit(); header("Location: card.php?id=".$object->id); exit; @@ -391,16 +394,10 @@ if (empty($reshook)) $_GET["commande_id"] = GETPOST('commande_id', 'int'); $action = 'create'; } - } - - /* - * Build a receiving receipt - */ - elseif ($action == 'create_delivery' && $conf->delivery_note->enabled && $user->rights->expedition->delivery->creer) - { + } elseif ($action == 'create_delivery' && $conf->delivery_note->enabled && $user->rights->expedition->delivery->creer) { + // Build a receiving receipt $result = $object->create_delivery($user); - if ($result > 0) - { + if ($result > 0) { header("Location: ".DOL_URL_ROOT.'/delivery/card.php?action=create_delivery&id='.$result); exit; } else { @@ -408,9 +405,8 @@ if (empty($reshook)) } } elseif ($action == 'confirm_valid' && $confirm == 'yes' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))) - ) - { + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))) + ) { $object->fetch_thirdparty(); $result = $object->valid($user); @@ -419,12 +415,15 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } else { // 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); @@ -433,57 +432,47 @@ 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); + } } } - } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->expedition->supprimer) - { + } elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->expedition->supprimer) { $also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0); $result = $object->cancel(0, $also_update_stock); - if ($result > 0) - { + if ($result > 0) { $result = $object->setStatut(-1); } else { setEventMessages($object->error, $object->errors, 'errors'); } - } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer) - { + } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->supprimer) { $also_update_stock = (GETPOST('alsoUpdateStock', 'alpha') ? 1 : 0); $result = $object->delete(0, $also_update_stock); - if ($result > 0) - { + if ($result > 0) { header("Location: ".DOL_URL_ROOT.'/expedition/index.php'); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } - } - // TODO add alternative status - /*elseif ($action == 'reopen' && (! empty($user->rights->expedition->creer) || ! empty($user->rights->expedition->shipping_advance->validate))) - { - $result = $object->setStatut(0); - if ($result < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - } - }*/ - - elseif ($action == 'setdate_livraison' && $user->rights->expedition->creer) - { + // TODO add alternative status + //} elseif ($action == 'reopen' && (! empty($user->rights->expedition->creer) || ! empty($user->rights->expedition->shipping_advance->validate))) + //{ + // $result = $object->setStatut(0); + // if ($result < 0) + // { + // setEventMessages($object->error, $object->errors, 'errors'); + // } + //} + } elseif ($action == 'setdate_livraison' && $user->rights->expedition->creer) { //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); $object->fetch($id); $result = $object->setDeliveryDate($user, $datedelivery); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - } - - // Action update - elseif ( - ($action == 'settracking_number' + } elseif (($action == 'settracking_number' || $action == 'settracking_url' || $action == 'settrueWeight' || $action == 'settrueWidth' @@ -491,28 +480,36 @@ if (empty($reshook)) || $action == 'settrueDepth' || $action == 'setshipping_method_id') && $user->rights->expedition->creer - ) - { + ) { + // Action update $error = 0; - if ($action == 'settracking_number') $object->tracking_number = trim(GETPOST('tracking_number', 'alpha')); - if ($action == 'settracking_url') $object->tracking_url = trim(GETPOST('tracking_url', 'int')); + if ($action == 'settracking_number') { + $object->tracking_number = trim(GETPOST('tracking_number', 'alpha')); + } + if ($action == 'settracking_url') { + $object->tracking_url = trim(GETPOST('tracking_url', 'int')); + } if ($action == 'settrueWeight') { $object->trueWeight = trim(GETPOST('trueWeight', 'int')); $object->weight_units = GETPOST('weight_units', 'int'); } - if ($action == 'settrueWidth') $object->trueWidth = trim(GETPOST('trueWidth', 'int')); + if ($action == 'settrueWidth') { + $object->trueWidth = trim(GETPOST('trueWidth', 'int')); + } if ($action == 'settrueHeight') { $object->trueHeight = trim(GETPOST('trueHeight', 'int')); $object->size_units = GETPOST('size_units', 'int'); } - if ($action == 'settrueDepth') $object->trueDepth = trim(GETPOST('trueDepth', 'int')); - if ($action == 'setshipping_method_id') $object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int')); + if ($action == 'settrueDepth') { + $object->trueDepth = trim(GETPOST('trueDepth', 'int')); + } + if ($action == 'setshipping_method_id') { + $object->shipping_method_id = trim(GETPOST('shipping_method_id', 'int')); + } - if (!$error) - { - if ($object->update($user) >= 0) - { + if (!$error) { + if ($object->update($user) >= 0) { header("Location: card.php?id=".$object->id); exit; } @@ -520,8 +517,7 @@ if (empty($reshook)) } $action = ""; - } elseif ($action == 'classifybilled') - { + } elseif ($action == 'classifybilled') { $object->fetch($id); $result = $object->setBilled(); if ($result >= 0) { @@ -529,8 +525,7 @@ if (empty($reshook)) exit(); } setEventMessages($object->error, $object->errors, 'errors'); - } elseif ($action == 'classifyclosed') - { + } elseif ($action == 'classifyclosed') { $object->fetch($id); $result = $object->setClosed(); if ($result >= 0) { @@ -538,37 +533,27 @@ if (empty($reshook)) exit(); } setEventMessages($object->error, $object->errors, 'errors'); - } - - /* - * delete a line - */ - elseif ($action == 'deleteline' && !empty($line_id)) - { + } elseif ($action == 'deleteline' && !empty($line_id)) { + // delete a line $object->fetch($id); $lines = $object->lines; $line = new ExpeditionLigne($db); $num_prod = count($lines); - for ($i = 0; $i < $num_prod; $i++) - { - if ($lines[$i]->id == $line_id) - { - if (count($lines[$i]->details_entrepot) > 1) - { + for ($i = 0; $i < $num_prod; $i++) { + if ($lines[$i]->id == $line_id) { + if (count($lines[$i]->details_entrepot) > 1) { // delete multi warehouse lines foreach ($lines[$i]->details_entrepot as $details_entrepot) { $line->id = $details_entrepot->line_id; - if (!$error && $line->delete($user) < 0) - { + if (!$error && $line->delete($user) < 0) { $error++; } } } else { // delete single warehouse line $line->id = $line_id; - if (!$error && $line->delete($user) < 0) - { + if (!$error && $line->delete($user) < 0) { $error++; } } @@ -582,13 +567,8 @@ if (empty($reshook)) } else { setEventMessages($line->error, $line->errors, 'errors'); } - } - - /* - * Update a line - */ - elseif ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save')) - { + } elseif ($action == 'updateline' && $user->rights->expedition->creer && GETPOST('save')) { + // Update a line // Clean parameters $qty = 0; $entrepot_id = 0; @@ -596,10 +576,8 @@ if (empty($reshook)) $lines = $object->lines; $num_prod = count($lines); - for ($i = 0; $i < $num_prod; $i++) - { - if ($lines[$i]->id == $line_id) // we have found line to update - { + for ($i = 0; $i < $num_prod; $i++) { + if ($lines[$i]->id == $line_id) { // we have found line to update $line = new ExpeditionLigne($db); // Extrafields Lines @@ -611,28 +589,25 @@ if (empty($reshook)) } } $line->fk_product = $lines[$i]->fk_product; - if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) - { + if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) { // line with lot - foreach ($lines[$i]->detail_batch as $detail_batch) - { + foreach ($lines[$i]->detail_batch as $detail_batch) { $lotStock = new Productbatch($db); $batch = "batchl".$detail_batch->fk_expeditiondet."_".$detail_batch->fk_origin_stock; $qty = "qtyl".$detail_batch->fk_expeditiondet.'_'.$detail_batch->id; $batch_id = GETPOST($batch, 'int'); $batch_qty = GETPOST($qty, 'int'); - if (!empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->qty)) - { - if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) // $line is ExpeditionLine - { - if ($lines[$i]->entrepot_id != 0) - { + if (!empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->qty)) { + if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) { // $line is ExpeditionLine + if ($lines[$i]->entrepot_id != 0) { // allow update line entrepot_id if not multi warehouse shipping $line->entrepot_id = $lotStock->warehouseid; } // detail_batch can be an object with keys, or an array of ExpeditionLineBatch - if (empty($line->detail_batch)) $line->detail_batch = new stdClass(); + if (empty($line->detail_batch)) { + $line->detail_batch = new stdClass(); + } $line->detail_batch->fk_origin_stock = $batch_id; $line->detail_batch->batch = $lotStock->batch; @@ -658,34 +633,25 @@ if (empty($reshook)) $batch_id = GETPOST($batch, 'int'); $batch_qty = GETPOST($qty, 'int'); $lineIdToAddLot = 0; - if ($batch_qty > 0 && !empty($batch_id)) - { - if ($lotStock->fetch($batch_id) > 0) - { + if ($batch_qty > 0 && !empty($batch_id)) { + if ($lotStock->fetch($batch_id) > 0) { // check if lotStock warehouse id is same as line warehouse id - if ($lines[$i]->entrepot_id > 0) - { + if ($lines[$i]->entrepot_id > 0) { // single warehouse shipment line - if ($lines[$i]->entrepot_id == $lotStock->warehouseid) - { + if ($lines[$i]->entrepot_id == $lotStock->warehouseid) { $lineIdToAddLot = $line_id; } - } elseif (count($lines[$i]->details_entrepot) > 1) - { + } elseif (count($lines[$i]->details_entrepot) > 1) { // multi warehouse shipment lines - foreach ($lines[$i]->details_entrepot as $detail_entrepot) - { - if ($detail_entrepot->entrepot_id == $lotStock->warehouseid) - { + foreach ($lines[$i]->details_entrepot as $detail_entrepot) { + if ($detail_entrepot->entrepot_id == $lotStock->warehouseid) { $lineIdToAddLot = $detail_entrepot->line_id; } } } - if ($lineIdToAddLot) - { + if ($lineIdToAddLot) { // add lot to existing line - if ($line->fetch($lineIdToAddLot) > 0) - { + if ($line->fetch($lineIdToAddLot) > 0) { $line->detail_batch->fk_origin_stock = $batch_id; $line->detail_batch->batch = $lotStock->batch; $line->detail_batch->entrepot_id = $lotStock->warehouseid; @@ -707,8 +673,7 @@ if (empty($reshook)) $line->detail_batch[0]->batch = $lotStock->batch; $line->detail_batch[0]->entrepot_id = $lotStock->warehouseid; $line->detail_batch[0]->qty = $batch_qty; - if ($object->create_line_batch($line, $line->array_options) < 0) - { + if ($object->create_line_batch($line, $line->array_options) < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } @@ -719,11 +684,9 @@ if (empty($reshook)) } } } else { - if ($lines[$i]->fk_product > 0) - { + if ($lines[$i]->fk_product > 0) { // line without lot - if ($lines[$i]->entrepot_id > 0) - { + if ($lines[$i]->entrepot_id > 0) { // single warehouse shipment line $stockLocation = "entl".$line_id; $qty = "qtyl".$line_id; @@ -736,17 +699,14 @@ if (empty($reshook)) } unset($_POST[$stockLocation]); unset($_POST[$qty]); - } elseif (count($lines[$i]->details_entrepot) > 1) - { + } elseif (count($lines[$i]->details_entrepot) > 1) { // multi warehouse shipment lines - foreach ($lines[$i]->details_entrepot as $detail_entrepot) - { + foreach ($lines[$i]->details_entrepot as $detail_entrepot) { if (!$error) { $stockLocation = "entl".$detail_entrepot->line_id; $qty = "qtyl".$detail_entrepot->line_id; $warehouse = GETPOST($stockLocation, 'int'); - if (!empty($warehouse)) - { + if (!empty($warehouse)) { $line->id = $detail_entrepot->line_id; $line->entrepot_id = $warehouse; $line->qty = GETPOST($qty, 'int'); @@ -783,10 +743,12 @@ if (empty($reshook)) // 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); @@ -807,7 +769,9 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Actions to send emails - if (empty($id)) $id = $facid; + if (empty($id)) { + $id = $facid; + } $triggersendname = 'SHIPPING_SENTBYMAIL'; $paramname = 'id'; $mode = 'emailfromshipment'; @@ -825,14 +789,15 @@ llxHeader('', $langs->trans('Shipment'), 'Expedition'); $form = new Form($db); $formfile = new FormFile($db); $formproduct = new FormProduct($db); -if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} $product_static = new Product($db); $shipment_static = new Expedition($db); $warehousestatic = new Entrepot($db); -if ($action == 'create2') -{ +if ($action == 'create2') { print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly'); print '
'.$langs->trans("ShipmentCreationIsDoneFromOrder"); @@ -840,31 +805,29 @@ if ($action == 'create2') } // Mode creation. -if ($action == 'create') -{ +if ($action == 'create') { $expe = new Expedition($db); print load_fiche_titre($langs->trans("CreateShipment"), '', 'dolly'); - if (!$origin) - { + if (!$origin) { setEventMessages($langs->trans("ErrorBadParameters"), null, 'errors'); } - if ($origin) - { + if ($origin) { $classname = ucfirst($origin); $object = new $classname($db); - if ($object->fetch($origin_id)) // This include the fetch_lines - { + if ($object->fetch($origin_id)) { // This include the fetch_lines $soc = new Societe($db); $soc->fetch($object->socid); $author = new User($db); $author->fetch($object->user_author_id); - if (!empty($conf->stock->enabled)) $entrepot = new Entrepot($db); + if (!empty($conf->stock->enabled)) { + $entrepot = new Entrepot($db); + } print '
'; print ''; @@ -872,8 +835,7 @@ if ($action == 'create') print ''; print ''; print ''; - if (GETPOST('entrepot_id', 'int')) - { + if (GETPOST('entrepot_id', 'int')) { print ''; } @@ -883,12 +845,10 @@ if ($action == 'create') // Ref print ''; - if ($origin == 'commande' && !empty($conf->commande->enabled)) - { + if ($origin == 'commande' && !empty($conf->commande->enabled)) { print $langs->trans("RefOrder"); } - if ($origin == 'propal' && !empty($conf->propal->enabled)) - { + if ($origin == 'propal' && !empty($conf->propal->enabled)) { print $langs->trans("RefProposal"); } print ''; @@ -898,9 +858,13 @@ if ($action == 'create') // Ref client print ''; - if ($origin == 'commande') print $langs->trans('RefCustomerOrder'); - elseif ($origin == 'propal') print $langs->trans('RefCustomerOrder'); - else print $langs->trans('RefCustomer'); + if ($origin == 'commande') { + print $langs->trans('RefCustomerOrder'); + } elseif ($origin == 'propal') { + print $langs->trans('RefCustomerOrder'); + } else { + print $langs->trans('RefCustomer'); + } print ''; print ''; print ''; @@ -912,11 +876,14 @@ if ($action == 'create') print ''; // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { $projectid = GETPOST('projectid', 'int') ?GETPOST('projectid', 'int') : 0; - if (empty($projectid) && !empty($object->fk_project)) $projectid = $object->fk_project; - if ($origin == 'project') $projectid = ($originid ? $originid : 0); + if (empty($projectid) && !empty($object->fk_project)) { + $projectid = $object->fk_project; + } + if ($origin == 'project') { + $projectid = ($originid ? $originid : 0); + } $langs->load("projects"); print ''; @@ -944,8 +911,7 @@ if ($action == 'create') print ""; // Note Private - if ($object->note_private && !$user->socid) - { + if ($object->note_private && !$user->socid) { print ''.$langs->trans("NotePrivate").''; print ''; $doleditor = new DolEditor('note_private', $object->note_private, '', 60, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%'); @@ -978,7 +944,9 @@ if ($action == 'create') print ''; $expe->fetch_delivery_methods(); print $form->selectarray("shipping_method_id", $expe->meths, GETPOST('shipping_method_id', 'int'), 1, 0, 0, "", 1); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } print "\n"; // Tracking number @@ -1002,8 +970,7 @@ if ($action == 'create') // Incoterms - if (!empty($conf->incoterm->enabled)) - { + if (!empty($conf->incoterm->enabled)) { print ''; print ''; print ''; @@ -1014,8 +981,7 @@ if ($action == 'create') // Document model include_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; $list = ModelePdfExpedition::liste_modeles($db); - if (count($list) > 1) - { + if (count($list) > 1) { print "".$langs->trans("DefaultModel").""; print ''; print $form->selectarray('model', $list, $conf->global->EXPEDITION_ADDON_PDF); @@ -1035,19 +1001,21 @@ if ($action == 'create') jQuery(document).ready(function() { jQuery("#autofill").click(function() {'; $i = 0; - while ($i < $numAsked) - { + while ($i < $numAsked) { print 'jQuery("#qtyl'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n"; - if (!empty($conf->productbatch->enabled)) print 'jQuery("#qtyl'.$i.'_'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n"; + if (!empty($conf->productbatch->enabled)) { + print 'jQuery("#qtyl'.$i.'_'.$i.'").val(jQuery("#qtyasked'.$i.'").val() - jQuery("#qtydelivered'.$i.'").val());'."\n"; + } $i++; } print '}); jQuery("#autoreset").click(function() { console.log("Reset values to 0"); '; $i = 0; - while ($i < $numAsked) - { + while ($i < $numAsked) { print 'jQuery("#qtyl'.$i.'").val(0);'."\n"; - if (!empty($conf->productbatch->enabled)) print 'jQuery("#qtyl'.$i.'_'.$i.'").val(0);'."\n"; + if (!empty($conf->productbatch->enabled)) { + print 'jQuery("#qtyl'.$i.'_'.$i.'").val(0);'."\n"; + } $i++; } print '}); @@ -1061,15 +1029,13 @@ if ($action == 'create') // Load shipments already done for same order $object->loadExpeditions(); - if ($numAsked) - { + if ($numAsked) { print ''; print ''.$langs->trans("Description").''; print ''.$langs->trans("QtyOrdered").''; print ''.$langs->trans("QtyShipped").''; print ''.$langs->trans("QtyToShip"); - if (empty($conf->productbatch->enabled)) - { + if (empty($conf->productbatch->enabled)) { print '
'.$langs->trans("Fill").''; print ' / '; } else { @@ -1077,10 +1043,8 @@ if ($action == 'create') } print ''.img_picto($langs->trans("Reset"), 'eraser').''; print ''; - if (!empty($conf->stock->enabled)) - { - if (empty($conf->productbatch->enabled)) - { + if (!empty($conf->stock->enabled)) { + if (empty($conf->productbatch->enabled)) { print ''.$langs->trans("Warehouse").' ('.$langs->trans("Stock").')'; } else { print ''.$langs->trans("Warehouse").' / '.$langs->trans("Batch").' ('.$langs->trans("Stock").')'; @@ -1090,31 +1054,34 @@ if ($action == 'create') } $indiceAsked = 0; - while ($indiceAsked < $numAsked) - { + while ($indiceAsked < $numAsked) { $product = new Product($db); $line = $object->lines[$indiceAsked]; $parameters = array('i' => $indiceAsked, 'line' => $line, 'num' => $numAsked); $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } - if (empty($reshook)) - { + if (empty($reshook)) { // Show product and description $type = $line->product_type ? $line->product_type : $line->fk_product_type; // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. - if (!empty($line->date_start)) $type = 1; - if (!empty($line->date_end)) $type = 1; + if (!empty($line->date_start)) { + $type = 1; + } + if (!empty($line->date_end)) { + $type = 1; + } print ''."\n"; print ''."\n"; // Product label - if ($line->fk_product > 0) // If predefined product - { + if ($line->fk_product > 0) { // If predefined product $product->fetch($line->fk_product); $product->load_stock('warehouseopen'); // Load all $product->stock_warehouse[idwarehouse]->detail_batch //var_dump($product->stock_warehouse[1]); @@ -1139,16 +1106,18 @@ if ($action == 'create') print_date_range($db->jdate($line->date_start), $db->jdate($line->date_end)); // Add description in form - if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) - { + if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) { print ($line->desc && $line->desc != $line->product_label) ? '
'.dol_htmlentitiesbr($line->desc) : ''; } print ''; } else { print ""; - if ($type == 1) $text = img_object($langs->trans('Service'), 'service'); - else $text = img_object($langs->trans('Product'), 'product'); + if ($type == 1) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } if (!empty($line->label)) { $text .= ' '.$line->label.''; @@ -1177,8 +1146,7 @@ if ($action == 'create') // Qty to ship $quantityAsked = $line->qty; - if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { + if ($line->product_type == 1 && empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $quantityToBeDelivered = 0; } else { $quantityToBeDelivered = $quantityAsked - $quantityDelivered; @@ -1186,37 +1154,37 @@ if ($action == 'create') $warehouse_id = GETPOST('entrepot_id', 'int'); $warehouseObject = null; - if ($warehouse_id > 0 || !($line->fk_product > 0) || empty($conf->stock->enabled)) // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection - { + if ($warehouse_id > 0 || !($line->fk_product > 0) || empty($conf->stock->enabled)) { // If warehouse was already selected or if product is not a predefined, we go into this part with no multiwarehouse selection print ''; //ship from preselected location $stock = + $product->stock_warehouse[$warehouse_id]->real; // Convert to number $deliverableQty = min($quantityToBeDelivered, $stock); - if ($deliverableQty < 0) $deliverableQty = 0; - if (empty($conf->productbatch->enabled) || !$product->hasbatch()) - { + if ($deliverableQty < 0) { + $deliverableQty = 0; + } + if (empty($conf->productbatch->enabled) || !$product->hasbatch()) { // Quantity to send print ''; - if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { - if (GETPOST('qtyl'.$indiceAsked, 'int')) $deliverableQty = GETPOST('qtyl'.$indiceAsked, 'int'); + if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + if (GETPOST('qtyl'.$indiceAsked, 'int')) { + $deliverableQty = GETPOST('qtyl'.$indiceAsked, 'int'); + } print ''; print ''; - } else print $langs->trans("NA"); + } else { + print $langs->trans("NA"); + } print ''; // Stock - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { print ''; - if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) // Type of product need stock change ? - { + if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { // Type of product need stock change ? // Show warehouse combo list $ent = "entl".$indiceAsked; $idl = "idl".$indiceAsked; $tmpentrepot_id = is_numeric(GETPOST($ent, 'int')) ?GETPOST($ent, 'int') : $warehouse_id; - if ($line->fk_product > 0) - { + if ($line->fk_product > 0) { print ''; $stockMin = false; @@ -1225,11 +1193,9 @@ if ($action == 'create') } print $formproduct->selectWarehouses($tmpentrepot_id, 'entl'.$indiceAsked, '', 1, 0, $line->fk_product, '', 1, 0, array(), 'minwidth200', '', 1, $stockMin, 'stock DESC, e.ref'); - if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id) - { + if ($tmpentrepot_id > 0 && $tmpentrepot_id == $warehouse_id) { //print $stock.' '.$quantityToBeDelivered; - if ($stock < $quantityToBeDelivered) - { + if ($stock < $quantityToBeDelivered) { print ' '.img_warning($langs->trans("StockTooLow")); // Stock too low for this $warehouse_id but you can change warehouse } } @@ -1243,18 +1209,14 @@ if ($action == 'create') print "\n"; // Show subproducts of product - if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0) - { + if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0) { $product->get_sousproduits_arbo(); $prods_arbo = $product->get_arbo_each_prod($qtyProdCom); - if (count($prods_arbo) > 0) - { - foreach ($prods_arbo as $key => $value) - { + if (count($prods_arbo) > 0) { + foreach ($prods_arbo as $key => $value) { //print $value[0]; $img = ''; - if ($value['stock'] < $value['stock_alert']) - { + if ($value['stock'] < $value['stock_alert']) { $img = img_warning($langs->trans("StockTooLow")); } print "      -> @@ -1270,23 +1232,21 @@ if ($action == 'create') print ''; $staticwarehouse = new Entrepot($db); - if ($warehouse_id > 0) $staticwarehouse->fetch($warehouse_id); + if ($warehouse_id > 0) { + $staticwarehouse->fetch($warehouse_id); + } $subj = 0; // Define nb of lines suggested for this order line $nbofsuggested = 0; - if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) - { - foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) - { + if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) { + foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) { $nbofsuggested++; } } print ''; - if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) - { - foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) // $dbatch is instance of Productbatch - { + if (is_object($product->stock_warehouse[$warehouse_id]) && count($product->stock_warehouse[$warehouse_id]->detail_batch)) { + foreach ($product->stock_warehouse[$warehouse_id]->detail_batch as $dbatch) { // $dbatch is instance of Productbatch //var_dump($dbatch); $batchStock = + $dbatch->qty; // To get a numeric $deliverableQty = min($quantityToBeDelivered, $batchStock); @@ -1315,8 +1275,7 @@ if ($action == 'create') print $detail; $quantityToBeDelivered -= $deliverableQty; - if ($quantityToBeDelivered < 0) - { + if ($quantityToBeDelivered < 0) { $quantityToBeDelivered = 0; } $subj++; @@ -1335,8 +1294,7 @@ if ($action == 'create') } } else { // ship from multiple locations - if (empty($conf->productbatch->enabled) || !$product->hasbatch()) - { + if (empty($conf->productbatch->enabled) || !$product->hasbatch()) { print ''; print ''."\n"; // end line and start a new one for each warehouse @@ -1344,38 +1302,33 @@ if ($action == 'create') $subj = 0; // Define nb of lines suggested for this order line $nbofsuggested = 0; - foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse) - { - if ($stock_warehouse->real > 0) - { + foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) { + if ($stock_warehouse->real > 0) { $nbofsuggested++; } } $tmpwarehouseObject = new Entrepot($db); - foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse) // $stock_warehouse is product_stock - { + foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) { // $stock_warehouse is product_stock $tmpwarehouseObject->fetch($warehouse_id); - if ($stock_warehouse->real > 0) - { + if ($stock_warehouse->real > 0) { $stock = + $stock_warehouse->real; // Convert it to number $deliverableQty = min($quantityToBeDelivered, $stock); $deliverableQty = max(0, $deliverableQty); // Quantity to send print ''; print ''; - if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { + if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { print ''; print ''; - } else print $langs->trans("NA"); + } else { + print $langs->trans("NA"); + } print ''; // Stock - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { print ''; - if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { + if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { print $tmpwarehouseObject->getNomUrl(0).' '; print ''; @@ -1386,8 +1339,7 @@ if ($action == 'create') print ''; } $quantityToBeDelivered -= $deliverableQty; - if ($quantityToBeDelivered < 0) - { + if ($quantityToBeDelivered < 0) { $quantityToBeDelivered = 0; } $subj++; @@ -1395,18 +1347,14 @@ if ($action == 'create') } } // Show subproducts of product (not recommanded) - if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0) - { + if (!empty($conf->global->PRODUIT_SOUSPRODUITS) && $line->fk_product > 0) { $product->get_sousproduits_arbo(); $prods_arbo = $product->get_arbo_each_prod($qtyProdCom); - if (count($prods_arbo) > 0) - { - foreach ($prods_arbo as $key => $value) - { + if (count($prods_arbo) > 0) { + foreach ($prods_arbo as $key => $value) { //print $value[0]; $img = ''; - if ($value['stock'] < $value['stock_alert']) - { + if ($value['stock'] < $value['stock_alert']) { $img = img_warning($langs->trans("StockTooLow")); } print ''; @@ -1429,25 +1377,23 @@ if ($action == 'create') $productlotObject = new Productlot($db); // Define nb of lines suggested for this order line $nbofsuggested = 0; - foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse) - { + foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) { if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) { - foreach ($stock_warehouse->detail_batch as $dbatch) - { + foreach ($stock_warehouse->detail_batch as $dbatch) { $nbofsuggested++; } } } - foreach ($product->stock_warehouse as $warehouse_id=>$stock_warehouse) - { + foreach ($product->stock_warehouse as $warehouse_id => $stock_warehouse) { $tmpwarehouseObject->fetch($warehouse_id); if (($stock_warehouse->real > 0) && (count($stock_warehouse->detail_batch))) { - foreach ($stock_warehouse->detail_batch as $dbatch) - { + foreach ($stock_warehouse->detail_batch as $dbatch) { //var_dump($dbatch); $batchStock = + $dbatch->qty; // To get a numeric $deliverableQty = min($quantityToBeDelivered, $batchStock); - if ($deliverableQty < 0) $deliverableQty = 0; + if ($deliverableQty < 0) { + $deliverableQty = 0; + } print ''; print ''; print ''; @@ -1462,12 +1408,14 @@ if ($action == 'create') //print '|'.$line->fk_product.'|'.$dbatch->batch.'|
'; print $langs->trans("Batch").': '; $result = $productlotObject->fetch(0, $line->fk_product, $dbatch->batch); - if ($result > 0) print $productlotObject->getNomUrl(1); - else print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed'; + if ($result > 0) { + print $productlotObject->getNomUrl(1); + } else { + print 'TableLotIncompleteRunRepairWithParamStandardEqualConfirmed'; + } print ' ('.$dbatch->qty.')'; $quantityToBeDelivered -= $deliverableQty; - if ($quantityToBeDelivered < 0) - { + if ($quantityToBeDelivered < 0) { $quantityToBeDelivered = 0; } //dol_syslog('deliverableQty = '.$deliverableQty.' batchStock = '.$batchStock); @@ -1477,18 +1425,15 @@ if ($action == 'create') } } } - if ($subj == 0) // Line not shown yet, we show it - { + if ($subj == 0) { // Line not shown yet, we show it $warehouse_selected_id = GETPOST('entrepot_id', 'int'); print ''; print ''; - if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { + if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $disabled = ''; - if (!empty($conf->productbatch->enabled) && $product->hasbatch()) - { + if (!empty($conf->productbatch->enabled) && $product->hasbatch()) { $disabled = 'disabled="disabled"'; } if ($warehouse_selected_id <= 0) { // We did not force a given warehouse, so we won't have no warehouse to change qty. @@ -1501,16 +1446,17 @@ if ($action == 'create') print ''; print ''; - if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { - if ($warehouse_selected_id > 0) - { + if ($line->product_type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { + if ($warehouse_selected_id > 0) { $warehouseObject = new Entrepot($db); $warehouseObject->fetch($warehouse_selected_id); print img_warning().' '.$langs->trans("NoProductToShipFoundIntoStock", $warehouseObject->label); } else { - if ($line->fk_product) print img_warning().' '.$langs->trans("StockTooLow"); - else print ''; + if ($line->fk_product) { + print img_warning().' '.$langs->trans("StockTooLow"); + } else { + print ''; + } } } else { print $langs->trans("Service"); @@ -1521,8 +1467,7 @@ if ($action == 'create') } // Line extrafield - if (!empty($extrafields)) - { + if (!empty($extrafields)) { //var_dump($line); $colspan = 5; $expLine = new ExpeditionLigne($db); @@ -1556,21 +1501,18 @@ if ($action == 'create') dol_print_error($db); } } -} elseif ($id || $ref) -/* *************************************************************************** */ -/* */ -/* Edit and view mode */ -/* */ -/* *************************************************************************** */ -{ +} elseif ($id || $ref) { + /* *************************************************************************** */ + /* */ + /* Edit and view mode */ + /* */ + /* *************************************************************************** */ $lines = $object->lines; $num_prod = count($lines); - if ($object->id > 0) - { - if (!empty($object->origin) && $object->origin_id > 0) - { + if ($object->id > 0) { + if (!empty($object->origin) && $object->origin_id > 0) { $typeobject = $object->origin; $origin = $object->origin; $origin_id = $object->origin_id; @@ -1588,8 +1530,7 @@ if ($action == 'create') $formconfirm = ''; // Confirm deleteion - if ($action == 'delete') - { + if ($action == 'delete') { $formquestion = array(); if ($object->statut == Expedition::STATUS_CLOSED && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { $formquestion = array( @@ -1613,11 +1554,9 @@ if ($action == 'create') } // Confirmation validation - if ($action == 'valid') - { + if ($action == 'valid') { $objectref = substr($object->ref, 1, 4); - if ($objectref == 'PROV') - { + if ($objectref == 'PROV') { $numref = $object->getNextNumRef($soc); } else { $numref = $object->ref; @@ -1625,8 +1564,7 @@ if ($action == 'create') $text = $langs->trans("ConfirmValidateSending", $numref); - if (!empty($conf->notification->enabled)) - { + if (!empty($conf->notification->enabled)) { require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; $notify = new Notify($db); $text .= '
'; @@ -1636,16 +1574,18 @@ if ($action == 'create') $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('ValidateSending'), $text, 'confirm_valid', '', 0, 1); } // Confirm cancelation - if ($action == 'cancel') - { + if ($action == 'cancel') { $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelSending'), $langs->trans("ConfirmCancelSending", $object->ref), 'confirm_cancel', '', 0, 1); } // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; - elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } // Print form confirm print $formconfirm; @@ -1657,13 +1597,11 @@ if ($action == 'create') $totalVolume = $tmparray['volume']; - if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) - { + if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) { $objectsrc = new Commande($db); $objectsrc->fetch($object->$typeobject->id); } - if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) - { + if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) { $objectsrc = new Propal($db); $objectsrc->fetch($object->$typeobject->id); } @@ -1723,8 +1661,7 @@ if ($action == 'create') print ''; // Linked documents - if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) - { + if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) { print ''; print '\n"; print ''; } - if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) - { + if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) { print ''; print ''; - if ($action != 'editdate_livraison') print ''; + if ($action != 'editdate_livraison') { + print ''; + } print '
'; print $langs->trans("RefOrder").''; @@ -1732,8 +1669,7 @@ if ($action == 'create') print "
'; print $langs->trans("RefProposal").''; @@ -1753,11 +1689,12 @@ if ($action == 'create') print $langs->trans('DateDeliveryPlanned'); print 'id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'
'; print ''; - if ($action == 'editdate_livraison') - { + if ($action == 'editdate_livraison') { print ''; print ''; print ''; @@ -1775,8 +1712,7 @@ if ($action == 'create') print $form->editfieldkey("Weight", 'trueWeight', $object->trueWeight, $object, $user->rights->expedition->creer); print ''; - if ($action == 'edittrueWeight') - { + if ($action == 'edittrueWeight') { print ''; print ''; print ''; @@ -1792,11 +1728,14 @@ if ($action == 'create') } // Calculated - if ($totalWeight > 0) - { - if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': '; + if ($totalWeight > 0) { + if (!empty($object->trueWeight)) { + print ' ('.$langs->trans("SumOfProductWeights").': '; + } print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no'); - if (!empty($object->trueWeight)) print ')'; + if (!empty($object->trueWeight)) { + print ')'; + } } print ''; @@ -1808,8 +1747,7 @@ if ($action == 'create') // Height print ''.$form->editfieldkey("Height", 'trueHeight', $object->trueHeight, $object, $user->rights->expedition->creer).''; - if ($action == 'edittrueHeight') - { + if ($action == 'edittrueHeight') { print ''; print ''; print ''; @@ -1839,25 +1777,27 @@ if ($action == 'create') print ''; $calculatedVolume = 0; $volumeUnit = 0; - if ($object->trueWidth && $object->trueHeight && $object->trueDepth) - { + if ($object->trueWidth && $object->trueHeight && $object->trueDepth) { $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth); $volumeUnit = $object->size_units * 3; } // If sending volume not defined we use sum of products - if ($calculatedVolume > 0) - { - if ($volumeUnit < 50) - { + if ($calculatedVolume > 0) { + if ($volumeUnit < 50) { print showDimensionInBestUnit($calculatedVolume, $volumeUnit, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no'); - } else print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit); + } else { + print $calculatedVolume.' '.measuringUnitString(0, "volume", $volumeUnit); + } } - if ($totalVolume > 0) - { - if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': '; + if ($totalVolume > 0) { + if ($calculatedVolume) { + print ' ('.$langs->trans("SumOfProductVolumes").': '; + } print showDimensionInBestUnit($totalVolume, 0, "volume", $langs, isset($conf->global->MAIN_VOLUME_DEFAULT_ROUND) ? $conf->global->MAIN_VOLUME_DEFAULT_ROUND : -1, isset($conf->global->MAIN_VOLUME_DEFAULT_UNIT) ? $conf->global->MAIN_VOLUME_DEFAULT_UNIT : 'no'); //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')'; - if ($calculatedVolume) print ')'; + if ($calculatedVolume) { + print ')'; + } } print "\n"; print ''; @@ -1881,22 +1821,24 @@ if ($action == 'create') print $langs->trans('SendingMethod'); print ''; - if ($action != 'editshipping_method_id') print 'id.'">'.img_edit($langs->trans('SetSendingMethod'), 1).''; + if ($action != 'editshipping_method_id') { + print 'id.'">'.img_edit($langs->trans('SetSendingMethod'), 1).''; + } print ''; print ''; - if ($action == 'editshipping_method_id') - { + if ($action == 'editshipping_method_id') { print ''; print ''; print ''; $object->fetch_delivery_methods(); print $form->selectarray("shipping_method_id", $object->meths, $object->shipping_method_id, 1, 0, 0, "", 1); - if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + if ($user->admin) { + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + } print ''; print '
'; } else { - if ($object->shipping_method_id > 0) - { + if ($object->shipping_method_id > 0) { // Get code using getLabelFromKey $code = $langs->getLabelFromKey($db, $object->shipping_method_id, 'c_shipment_mode', 'rowid', 'code'); print $langs->trans("SendingMethod".strtoupper($code)); @@ -1911,19 +1853,20 @@ if ($action == 'create') print ''; // Incoterms - if (!empty($conf->incoterm->enabled)) - { + if (!empty($conf->incoterm->enabled)) { print ''; print '
'; print $langs->trans('IncotermLabel'); print ''; - if ($user->rights->expedition->creer) print ''.img_edit().''; - else print ' '; + if ($user->rights->expedition->creer) { + print ''.img_edit().''; + } else { + print ' '; + } print '
'; print ''; print ''; - if ($action != 'editincoterm') - { + if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); } else { print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); @@ -1947,8 +1890,7 @@ if ($action == 'create') // Lines of products - if ($action == 'editline') - { + if ($action == 'editline') { print '
@@ -1963,76 +1905,72 @@ if ($action == 'create') print ''; print ''; // Adds a line numbering column - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) - { + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print ' '; } // Product/Service print ''.$langs->trans("Products").''; // Qty print ''.$langs->trans("QtyOrdered").''; - if ($origin && $origin_id > 0) - { + if ($origin && $origin_id > 0) { print ''.$langs->trans("QtyInOtherShipments").''; } - if ($action == 'editline') - { + if ($action == 'editline') { $editColspan = 3; - if (empty($conf->stock->enabled)) $editColspan--; - if (empty($conf->productbatch->enabled)) $editColspan--; + if (empty($conf->stock->enabled)) { + $editColspan--; + } + if (empty($conf->productbatch->enabled)) { + $editColspan--; + } print ''; - if ($object->statut <= 1) - { + if ($object->statut <= 1) { print $langs->trans("QtyToShip").' - '; } else { print $langs->trans("QtyShipped").' - '; } - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { print $langs->trans("WarehouseSource").' - '; } - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { print $langs->trans("Batch"); } print ''; } else { - if ($object->statut <= 1) - { + if ($object->statut <= 1) { print ''.$langs->trans("QtyToShip").''; } else { print ''.$langs->trans("QtyShipped").''; } - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { print ''.$langs->trans("WarehouseSource").''; } - if (!empty($conf->productbatch->enabled)) - { + if (!empty($conf->productbatch->enabled)) { print ''.$langs->trans("Batch").''; } } print ''.$langs->trans("CalculatedWeight").''; print ''.$langs->trans("CalculatedVolume").''; //print ''.$langs->trans("Size").''; - if ($object->statut == 0) - { + if ($object->statut == 0) { print ''; print ''; } print "\n"; print ''; - if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) - { + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $object->fetch_thirdparty(); $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); - if (empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) - { + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) { + $newlang = GETPOST('lang_id', 'aZ09'); + } + if (empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } @@ -2040,8 +1978,7 @@ if ($action == 'create') // Get list of products already sent for same source object into $alreadysent $alreadysent = array(); - if ($origin && $origin_id > 0) - { + if ($origin && $origin_id > 0) { $sql = "SELECT obj.rowid, obj.fk_product, obj.label, obj.description, obj.product_type as fk_product_type, obj.qty as qty_asked, obj.date_start, obj.date_end"; $sql .= ", ed.rowid as shipmentline_id, ed.qty as qty_shipped, ed.fk_expedition as expedition_id, ed.fk_origin_line, ed.fk_entrepot"; $sql .= ", e.rowid as shipment_id, e.ref as shipment_ref, e.date_creation, e.date_valid, e.date_delivery, e.date_expedition"; @@ -2062,16 +1999,13 @@ if ($action == 'create') dol_syslog("get list of shipment lines", LOG_DEBUG); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); - if ($obj) - { + if ($obj) { // $obj->rowid is rowid in $origin."det" table $alreadysent[$obj->rowid][$obj->shipmentline_id] = array( 'shipment_ref'=>$obj->shipment_ref, 'shipment_id'=>$obj->shipment_id, 'warehouse'=>$obj->fk_entrepot, 'qty_shipped'=>$obj->qty_shipped, @@ -2087,33 +2021,32 @@ if ($action == 'create') print ''; // Loop on each product to send/sent - for ($i = 0; $i < $num_prod; $i++) - { + for ($i = 0; $i < $num_prod; $i++) { $parameters = array('i' => $i, 'line' => $lines[$i], 'line_id' => $line_id, 'num' => $num_prod, 'alreadysent' => $alreadysent, 'editColspan' => $editColspan, 'outputlangs' => $outputlangs); $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } - if (empty($reshook)) - { + if (empty($reshook)) { print ''; // id of order line print ''; // # - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) - { + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print ''.($i + 1).''; } // Predefined product or service - if ($lines[$i]->fk_product > 0) - { + if ($lines[$i]->fk_product > 0) { // Define output language - if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) - { + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $prod = new Product($db); $prod->fetch($lines[$i]->fk_product); $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $lines[$i]->product_label; - } else $label = (!empty($lines[$i]->label) ? $lines[$i]->label : $lines[$i]->product_label); + } else { + $label = (!empty($lines[$i]->label) ? $lines[$i]->label : $lines[$i]->product_label); + } print ''; @@ -2143,15 +2076,17 @@ if ($action == 'create') $description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($lines[$i]->description)); print $form->textwithtooltip($text, $description, 3, '', '', $i); print_date_range($lines[$i]->date_start, $lines[$i]->date_end); - if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) - { + if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) { print (!empty($lines[$i]->description) && $lines[$i]->description != $lines[$i]->product) ? '
'.dol_htmlentitiesbr($lines[$i]->description) : ''; } print "\n"; } else { print ''; - if ($lines[$i]->product_type == Product::TYPE_SERVICE) $text = img_object($langs->trans('Service'), 'service'); - else $text = img_object($langs->trans('Product'), 'product'); + if ($lines[$i]->product_type == Product::TYPE_SERVICE) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } if (!empty($lines[$i]->label)) { $text .= ' '.$lines[$i]->label.''; @@ -2168,26 +2103,25 @@ if ($action == 'create') print ''.$lines[$i]->qty_asked.''; // Qty in other shipments (with shipment and warehouse used) - if ($origin && $origin_id > 0) - { + if ($origin && $origin_id > 0) { print ''; - foreach ($alreadysent as $key => $val) - { - if ($lines[$i]->fk_origin_line == $key) - { + foreach ($alreadysent as $key => $val) { + if ($lines[$i]->fk_origin_line == $key) { $j = 0; - foreach ($val as $shipmentline_id=> $shipmentline_var) - { - if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) continue; // We want to show only "other shipments" + foreach ($val as $shipmentline_id => $shipmentline_var) { + if ($shipmentline_var['shipment_id'] == $lines[$i]->fk_expedition) { + continue; // We want to show only "other shipments" + } $j++; - if ($j > 1) print '
'; + if ($j > 1) { + print '
'; + } $shipment_static->fetch($shipmentline_var['shipment_id']); print $shipment_static->getNomUrl(1); print ' - '.$shipmentline_var['qty_shipped']; $htmltext = $langs->trans("DateValidation").' : '.(empty($shipmentline_var['date_valid']) ? $langs->trans("Draft") : dol_print_date($shipmentline_var['date_valid'], 'dayhour')); - if (!empty($conf->stock->enabled) && $shipmentline_var['warehouse'] > 0) - { + if (!empty($conf->stock->enabled) && $shipmentline_var['warehouse'] > 0) { $warehousestatic->fetch($shipmentline_var['warehouse']); $htmltext .= '
'.$langs->trans("FromLocation").' : '.$warehousestatic->getNomUrl(1, '', 0, 1); } @@ -2198,22 +2132,18 @@ if ($action == 'create') print ''; } - if ($action == 'editline' && $lines[$i]->id == $line_id) - { + if ($action == 'editline' && $lines[$i]->id == $line_id) { // edit mode print ''; - if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) - { + if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) { print ''; $line = new ExpeditionLigne($db); - foreach ($lines[$i]->detail_batch as $detail_batch) - { + foreach ($lines[$i]->detail_batch as $detail_batch) { print ''; // Qty to ship or shipped print ''; // Batch number managment - if ($lines[$i]->entrepot_id == 0) - { + if ($lines[$i]->entrepot_id == 0) { // only show lot numbers from src warehouse when shipping from multiple warehouses $line->fetch($detail_batch->fk_expeditiondet); } @@ -2227,12 +2157,9 @@ if ($action == 'create') // Batch number managment print ''; print ''; - } elseif (!empty($conf->stock->enabled)) - { - if ($lines[$i]->fk_product > 0) - { - if ($lines[$i]->entrepot_id > 0) - { + } elseif (!empty($conf->stock->enabled)) { + if ($lines[$i]->fk_product > 0) { + if ($lines[$i]->entrepot_id > 0) { print ''; print ''; // Qty to ship or shipped @@ -2242,11 +2169,9 @@ if ($action == 'create') // Batch number managment print ''; print ''; - } elseif (count($lines[$i]->details_entrepot) > 1) - { + } elseif (count($lines[$i]->details_entrepot) > 1) { print ''; - foreach ($lines[$i]->details_entrepot as $detail_entrepot) - { + foreach ($lines[$i]->details_entrepot as $detail_entrepot) { print ''; // Qty to ship or shipped print ''; @@ -2279,21 +2204,16 @@ if ($action == 'create') print ''; // Warehouse source - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { print ''; // Volume print ''; // Size //print ''; - if ($action == 'editline' && $lines[$i]->id == $line_id) - { + if ($action == 'editline' && $lines[$i]->id == $line_id) { print ''; - } elseif ($object->statut == Expedition::STATUS_DRAFT) - { + } elseif ($object->statut == Expedition::STATUS_DRAFT) { // edit-delete buttons print ''; // Display lines extrafields - if (!empty($rowExtrafieldsStart)) - { + if (!empty($rowExtrafieldsStart)) { print $rowExtrafieldsStart; print $rowExtrafieldsView; print $rowEnd; @@ -2381,15 +2300,20 @@ if ($action == 'create') // Display lines extrafields if (!empty($extrafields)) { $colspan = 6; - if ($origin && $origin_id > 0) $colspan++; - if (!empty($conf->productbatch->enabled)) $colspan++; - if (!empty($conf->stock->enabled)) $colspan++; + if ($origin && $origin_id > 0) { + $colspan++; + } + if (!empty($conf->productbatch->enabled)) { + $colspan++; + } + if (!empty($conf->stock->enabled)) { + $colspan++; + } $line = $lines[$i]; $line->fetch_optionals(); - if ($action == 'editline' && $line->id == $line_id) - { + if ($action == 'editline' && $line->id == $line_id) { print $lines[$i]->showOptionals($extrafields, 'edit', array('colspan'=>$colspan), $indiceAsked); } else { print $lines[$i]->showOptionals($extrafields, 'view', array('colspan'=>$colspan), $indiceAsked); @@ -2416,20 +2340,16 @@ if ($action == 'create') * Boutons actions */ - if (($user->socid == 0) && ($action != 'presend')) - { + if (($user->socid == 0) && ($action != 'presend')) { print '
'; $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->statut == Expedition::STATUS_DRAFT && $num_prod > 0) - { + if (empty($reshook)) { + if ($object->statut == Expedition::STATUS_DRAFT && $num_prod > 0) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))) - { + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate))) { print ''.$langs->trans("Validate").''; } else { print ''.$langs->trans("Validate").''; @@ -2438,10 +2358,8 @@ if ($action == 'create') // TODO add alternative status // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order) - if ($object->statut == Expedition::STATUS_CLOSED && $user->rights->expedition->creer) - { - if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? - { + if ($object->statut == Expedition::STATUS_CLOSED && $user->rights->expedition->creer) { + if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? print ''.$langs->trans("ClassifyUnbilled").''; } else { print ''.$langs->trans("ReOpen").''; @@ -2450,20 +2368,18 @@ if ($action == 'create') // Send if (empty($user->socid)) { - if ($object->statut > 0) - { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send) - { + if ($object->statut > 0) { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send) { print ''.$langs->trans('SendMail').''; - } else print ''.$langs->trans('SendMail').''; + } else { + print ''.$langs->trans('SendMail').''; + } } } // Create bill - if (!empty($conf->facture->enabled) && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED)) - { - if ($user->rights->facture->creer) - { + if (!empty($conf->facture->enabled) && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED)) { + if ($user->rights->facture->creer) { // TODO show button only if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // If we do that, we must also make this option official. print ''.$langs->trans("CreateBill").''; @@ -2472,19 +2388,15 @@ if ($action == 'create') // This is just to generate a delivery receipt //var_dump($object->linkedObjectsIds['delivery']); - if ($conf->delivery_note->enabled && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED) && $user->rights->expedition->delivery->creer && empty($object->linkedObjectsIds['delivery'])) - { + if ($conf->delivery_note->enabled && ($object->statut == Expedition::STATUS_VALIDATED || $object->statut == Expedition::STATUS_CLOSED) && $user->rights->expedition->delivery->creer && empty($object->linkedObjectsIds['delivery'])) { print ''.$langs->trans("CreateDeliveryOrder").''; } // Close - if ($object->statut == Expedition::STATUS_VALIDATED) - { - if ($user->rights->expedition->creer && $object->statut > 0 && !$object->billed) - { + if ($object->statut == Expedition::STATUS_VALIDATED) { + if ($user->rights->expedition->creer && $object->statut > 0 && !$object->billed) { $label = "Close"; $paramaction = 'classifyclosed'; // = Transferred/Received // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders - if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? - { + if (!empty($conf->facture->enabled) && !empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { // Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close ? $label = "ClassifyBilled"; $paramaction = 'classifybilled'; } @@ -2493,17 +2405,14 @@ if ($action == 'create') } // Cancel - if ($object->statut == Expedition::STATUS_VALIDATED) - { - if ($user->rights->expedition->supprimer) - { + if ($object->statut == Expedition::STATUS_VALIDATED) { + if ($user->rights->expedition->supprimer) { print ''.$langs->trans("Cancel").''; } } // Delete - if ($user->rights->expedition->supprimer) - { + if ($user->rights->expedition->supprimer) { print ''.$langs->trans("Delete").''; } } @@ -2516,8 +2425,7 @@ if ($action == 'create') * Documents generated */ - if ($action != 'presend' && $action != 'editline') - { + if ($action != 'presend' && $action != 'editline') { print '
'; $objectref = dol_sanitizeFileName($object->ref); diff --git a/htdocs/expedition/class/api_shipments.class.php b/htdocs/expedition/class/api_shipments.class.php index 22acaeaa26b..42564f7dd72 100644 --- a/htdocs/expedition/class/api_shipments.class.php +++ b/htdocs/expedition/class/api_shipments.class.php @@ -32,7 +32,7 @@ class Shipments extends DolibarrApi /** * @var array $FIELDS Mandatory fields, checked when create and update object */ - static $FIELDS = array( + public static $FIELDS = array( 'socid', 'origin_id', 'origin_type', @@ -110,28 +110,37 @@ class Shipments 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."expedition 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 + } $sql .= ' WHERE t.entity IN ('.getEntity('expedition').')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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 && !$socids) || $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 + } // 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 = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; @@ -140,8 +149,7 @@ class Shipments extends DolibarrApi $sql .= $this->db->order($sortfield, $sortorder); if ($limit) { - if ($page < 0) - { + if ($page < 0) { $page = 0; } $offset = $limit * $page; @@ -152,13 +160,11 @@ class Shipments extends DolibarrApi dol_syslog("API Rest request"); $result = $this->db->query($sql); - if ($result) - { + if ($result) { $num = $this->db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); $i = 0; - while ($i < $min) - { + while ($i < $min) { $obj = $this->db->fetch_object($result); $shipment_static = new Expedition($this->db); if ($shipment_static->fetch($obj->rowid)) { @@ -217,28 +223,28 @@ class Shipments extends DolibarrApi // * @return int // */ /* - public function getLines($id) - { - if(! DolibarrApiAccess::$user->rights->expedition->lire) { - throw new RestException(401); - } + public function getLines($id) + { + if(! DolibarrApiAccess::$user->rights->expedition->lire) { + throw new RestException(401); + } - $result = $this->shipment->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Shipment not found'); - } + $result = $this->shipment->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Shipment not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - $this->shipment->getLinesArray(); - $result = array(); - foreach ($this->shipment->lines as $line) { - array_push($result,$this->_cleanObjectDatas($line)); - } - return $result; - } - */ + if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->shipment->getLinesArray(); + $result = array(); + foreach ($this->shipment->lines as $line) { + array_push($result,$this->_cleanObjectDatas($line)); + } + return $result; + } + */ // /** // * Add a line to given shipment @@ -251,56 +257,56 @@ class Shipments extends DolibarrApi // * @return int // */ /* - public function postLine($id, $request_data = null) - { - if(! DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } + public function postLine($id, $request_data = null) + { + if(! DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } - $result = $this->shipment->fetch($id); - if ( ! $result ) { - throw new RestException(404, 'Shipment not found'); - } + $result = $this->shipment->fetch($id); + if ( ! $result ) { + throw new RestException(404, 'Shipment not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - $request_data = (object) $request_data; - $updateRes = $this->shipment->addline( - $request_data->desc, - $request_data->subprice, - $request_data->qty, - $request_data->tva_tx, - $request_data->localtax1_tx, - $request_data->localtax2_tx, - $request_data->fk_product, - $request_data->remise_percent, - $request_data->info_bits, - $request_data->fk_remise_except, - 'HT', - 0, - $request_data->date_start, - $request_data->date_end, - $request_data->product_type, - $request_data->rang, - $request_data->special_code, - $fk_parent_line, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, - $request_data->array_options, - $request_data->fk_unit, - $request_data->origin, - $request_data->origin_id, - $request_data->multicurrency_subprice - ); + if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->shipment->addline( + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + $request_data->fk_product, + $request_data->remise_percent, + $request_data->info_bits, + $request_data->fk_remise_except, + 'HT', + 0, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->rang, + $request_data->special_code, + $fk_parent_line, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->array_options, + $request_data->fk_unit, + $request_data->origin, + $request_data->origin_id, + $request_data->multicurrency_subprice + ); - if ($updateRes > 0) { - return $updateRes; + if ($updateRes > 0) { + return $updateRes; - } - return false; - }*/ + } + return false; + }*/ // /** // * Update a line to given shipment @@ -314,53 +320,53 @@ class Shipments extends DolibarrApi // * @return object // */ /* - public function putLine($id, $lineid, $request_data = null) - { - if (! DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } + public function putLine($id, $lineid, $request_data = null) + { + if (! DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } - $result = $this->shipment->fetch($id); - if ( ! $result ) { - throw new RestException(404, 'Shipment not found'); - } + $result = $this->shipment->fetch($id); + if ( ! $result ) { + throw new RestException(404, 'Shipment not found'); + } - if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - $request_data = (object) $request_data; - $updateRes = $this->shipment->updateline( - $lineid, - $request_data->desc, - $request_data->subprice, - $request_data->qty, - $request_data->remise_percent, - $request_data->tva_tx, - $request_data->localtax1_tx, - $request_data->localtax2_tx, - 'HT', - $request_data->info_bits, - $request_data->date_start, - $request_data->date_end, - $request_data->product_type, - $request_data->fk_parent_line, - 0, - $request_data->fk_fournprice, - $request_data->pa_ht, - $request_data->label, - $request_data->special_code, - $request_data->array_options, - $request_data->fk_unit, - $request_data->multicurrency_subprice - ); + if( ! DolibarrApi::_checkAccessToResource('expedition',$this->shipment->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->shipment->updateline( + $lineid, + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->remise_percent, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + 'HT', + $request_data->info_bits, + $request_data->date_start, + $request_data->date_end, + $request_data->product_type, + $request_data->fk_parent_line, + 0, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->special_code, + $request_data->array_options, + $request_data->fk_unit, + $request_data->multicurrency_subprice + ); - if ($updateRes > 0) { - $result = $this->get($id); - unset($result->line); - return $this->_cleanObjectDatas($result); - } - return false; - }*/ + if ($updateRes > 0) { + $result = $this->get($id); + unset($result->line); + return $this->_cleanObjectDatas($result); + } + return false; + }*/ /** * Delete a line to given shipment @@ -425,12 +431,13 @@ class Shipments extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } foreach ($request_data as $field => $value) { - if ($field == 'id') continue; + if ($field == 'id') { + continue; + } $this->shipment->$field = $value; } - if ($this->shipment->update(DolibarrApiAccess::$user) > 0) - { + if ($this->shipment->update(DolibarrApiAccess::$user) > 0) { return $this->get($id); } else { throw new RestException(500, $this->shipment->error); @@ -539,27 +546,27 @@ class Shipments extends DolibarrApi // * @throws RestException 405 // */ /* - public function setinvoiced($id) - { + public function setinvoiced($id) + { - if(! DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } - if(empty($id)) { - throw new RestException(400, 'Shipment ID is mandatory'); - } - $result = $this->shipment->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Shipment not found'); - } + if(! DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Shipment ID is mandatory'); + } + $result = $this->shipment->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Shipment not found'); + } - $result = $this->shipment->classifyBilled(DolibarrApiAccess::$user); - if( $result < 0) { - throw new RestException(400, $this->shipment->error); - } - return $result; - } - */ + $result = $this->shipment->classifyBilled(DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(400, $this->shipment->error); + } + return $result; + } + */ // /** @@ -576,35 +583,35 @@ class Shipments extends DolibarrApi // * @throws RestException 405 // */ /* - public function createShipmentFromOrder($orderid) - { + public function createShipmentFromOrder($orderid) + { - require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; + require_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php'; - if(! DolibarrApiAccess::$user->rights->expedition->lire) { - throw new RestException(401); - } - if(! DolibarrApiAccess::$user->rights->expedition->creer) { - throw new RestException(401); - } - if(empty($proposalid)) { - throw new RestException(400, 'Order ID is mandatory'); - } + if(! DolibarrApiAccess::$user->rights->expedition->lire) { + throw new RestException(401); + } + if(! DolibarrApiAccess::$user->rights->expedition->creer) { + throw new RestException(401); + } + if(empty($proposalid)) { + throw new RestException(400, 'Order ID is mandatory'); + } - $order = new Commande($this->db); - $result = $order->fetch($proposalid); - if( ! $result ) { - throw new RestException(404, 'Order not found'); - } + $order = new Commande($this->db); + $result = $order->fetch($proposalid); + if( ! $result ) { + throw new RestException(404, 'Order not found'); + } - $result = $this->shipment->createFromOrder($order, DolibarrApiAccess::$user); - if( $result < 0) { - throw new RestException(405, $this->shipment->error); - } - $this->shipment->fetchObjectLinked(); - return $this->_cleanObjectDatas($this->shipment); - } - */ + $result = $this->shipment->createFromOrder($order, DolibarrApiAccess::$user); + if( $result < 0) { + throw new RestException(405, $this->shipment->error); + } + $this->shipment->fetchObjectLinked(); + return $this->_cleanObjectDatas($this->shipment); + } + */ // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore /** @@ -627,10 +634,8 @@ class Shipments extends DolibarrApi unset($object->barcode_type_label); unset($object->barcode_type_coder); - if (!empty($object->lines) && is_array($object->lines)) - { - foreach ($object->lines as $line) - { + if (!empty($object->lines) && is_array($object->lines)) { + foreach ($object->lines as $line) { unset($line->tva_tx); unset($line->vat_src_code); unset($line->total_ht); @@ -656,8 +661,9 @@ class Shipments extends DolibarrApi { $shipment = array(); foreach (Shipments::$FIELDS as $field) { - if (!isset($data[$field])) + if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); + } $shipment[$field] = $data[$field]; } return $shipment; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index df2e3f347e0..a79ee76a2fa 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -37,9 +37,15 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; require_once DOL_DOCUMENT_ROOT."/core/class/commonobjectline.class.php"; require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php'; -if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; +if (!empty($conf->propal->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +} +if (!empty($conf->commande->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; +} +if (!empty($conf->productbatch->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; +} /** @@ -231,8 +237,7 @@ class Expedition extends CommonObject global $langs, $conf; $langs->load("sendings"); - if (!empty($conf->global->EXPEDITION_ADDON_NUMBER)) - { + if (!empty($conf->global->EXPEDITION_ADDON_NUMBER)) { $mybool = false; $file = $conf->global->EXPEDITION_ADDON_NUMBER.".php"; @@ -248,8 +253,7 @@ class Expedition extends CommonObject $mybool |= @include_once $dir.$file; } - if (!$mybool) - { + if (!$mybool) { dol_print_error('', "Failed to include file ".$file); return ''; } @@ -258,8 +262,7 @@ class Expedition extends CommonObject $numref = ""; $numref = $obj->getNextValue($soc, $this); - if ($numref != "") - { + if ($numref != "") { return $numref; } else { dol_print_error($this->db, get_class($this)."::getNextNumRef ".$obj->error); @@ -290,7 +293,9 @@ class Expedition extends CommonObject // Clean parameters $this->brouillon = 1; $this->tracking_number = dol_sanitizeFileName($this->tracking_number); - if (empty($this->fk_project)) $this->fk_project = 0; + if (empty($this->fk_project)) { + $this->fk_project = 0; + } $this->user = $user; @@ -353,8 +358,7 @@ class Expedition extends CommonObject 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."expedition"); $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; @@ -362,59 +366,49 @@ class Expedition extends CommonObject $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::create", LOG_DEBUG); - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { // Insert of lines $num = count($this->lines); - for ($i = 0; $i < $num; $i++) - { - if (!isset($this->lines[$i]->detail_batch)) - { // no batch management - if (!$this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->rang, $this->lines[$i]->array_options) > 0) - { + for ($i = 0; $i < $num; $i++) { + if (!isset($this->lines[$i]->detail_batch)) { // no batch management + if (!$this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty, $this->lines[$i]->rang, $this->lines[$i]->array_options) > 0) { $error++; } } else { // with batch management - if (!$this->create_line_batch($this->lines[$i], $this->lines[$i]->array_options) > 0) - { + if (!$this->create_line_batch($this->lines[$i], $this->lines[$i]->array_options) > 0) { $error++; } } } - if (!$error && $this->id && $this->origin_id) - { + if (!$error && $this->id && $this->origin_id) { $ret = $this->add_object_linked(); - if (!$ret) - { + if (!$ret) { $error++; } } // Actions on extra fields - 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('SHIPPING_CREATE', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers - if (!$error) - { + if (!$error) { $this->db->commit(); return $this->id; } else { - foreach ($this->errors as $errmsg) - { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -465,8 +459,7 @@ class Expedition extends CommonObject $expeditionline->rang = $rang; $expeditionline->array_options = $array_options; - if (($lineId = $expeditionline->insert($user)) < 0) - { + if (($lineId = $expeditionline->insert($user)) < 0) { $this->errors[] = $expeditionline->error; } return $lineId; @@ -489,26 +482,21 @@ class Expedition extends CommonObject $tab = $line_ext->detail_batch; // create stockLocation Qty array - foreach ($tab as $detbatch) - { - if ($detbatch->entrepot_id) - { + foreach ($tab as $detbatch) { + if ($detbatch->entrepot_id) { $stockLocationQty[$detbatch->entrepot_id] += $detbatch->qty; } } // create shipment lines - foreach ($stockLocationQty as $stockLocation => $qty) - { + foreach ($stockLocationQty as $stockLocation => $qty) { $line_id = $this->create_line($stockLocation, $line_ext->origin_line_id, $qty, $line_ext->rang, $array_options); if ($line_id < 0) { $error++; } else { // create shipment batch lines for stockLocation - foreach ($tab as $detbatch) - { + foreach ($tab as $detbatch) { if ($detbatch->entrepot_id == $stockLocation) { - if (!($detbatch->create($line_id) > 0)) // Create an expeditionlinebatch - { + if (!($detbatch->create($line_id) > 0)) { // Create an expeditionlinebatch $error++; } } @@ -516,8 +504,11 @@ class Expedition extends CommonObject } } - if (!$error) return 1; - else return -1; + if (!$error) { + return 1; + } else { + return -1; + } } /** @@ -534,7 +525,9 @@ class Expedition extends CommonObject global $conf; // Check parameters - if (empty($id) && empty($ref) && empty($ref_ext)) return -1; + if (empty($id) && empty($ref) && empty($ref_ext)) { + return -1; + } $sql = "SELECT e.rowid, e.entity, e.ref, e.fk_soc as socid, e.date_creation, e.ref_customer, e.ref_ext, e.ref_int, e.fk_user_author, e.fk_statut, e.fk_projet as fk_project, e.billed"; $sql .= ", e.date_valid"; @@ -551,17 +544,23 @@ class Expedition extends CommonObject $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON e.fk_incoterms = i.rowid'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_shipment_mode as s ON e.fk_shipping_method = s.rowid'; $sql .= " WHERE e.entity IN (".getEntity('expedition').")"; - if ($id) $sql .= " AND e.rowid=".$id; - if ($ref) $sql .= " AND e.ref='".$this->db->escape($ref)."'"; - if ($ref_ext) $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; - if ($notused) $sql .= " AND e.ref_int='".$this->db->escape($notused)."'"; + if ($id) { + $sql .= " AND e.rowid=".$id; + } + if ($ref) { + $sql .= " AND e.ref='".$this->db->escape($ref)."'"; + } + if ($ref_ext) { + $sql .= " AND e.ref_ext='".$this->db->escape($ref_ext)."'"; + } + if ($notused) { + $sql .= " AND e.ref_int='".$this->db->escape($notused)."'"; + } dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $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; @@ -614,7 +613,9 @@ class Expedition extends CommonObject $this->db->free($result); - if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1; + if ($this->statut == self::STATUS_DRAFT) { + $this->brouillon = 1; + } // Tracking url $this->getUrlTrackingStatus($obj->tracking_number); @@ -626,18 +627,20 @@ class Expedition extends CommonObject $this->fetch_optionals(); // Fix Get multicurrency param for transmited - if (!empty($conf->multicurrency->enabled)) - { - if (!empty($this->multicurrency_code)) $this->multicurrency_code = $this->thirdparty->multicurrency_code; - if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($this->thirdparty->multicurrency_tx)) $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; + if (!empty($conf->multicurrency->enabled)) { + if (!empty($this->multicurrency_code)) { + $this->multicurrency_code = $this->thirdparty->multicurrency_code; + } + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($this->thirdparty->multicurrency_tx)) { + $this->multicurrency_tx = $this->thirdparty->multicurrency_tx; + } } /* * Lines */ $result = $this->fetch_lines(); - if ($result < 0) - { + if ($result < 0) { return -3; } @@ -669,15 +672,13 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::valid"); // Protection - if ($this->statut) - { + if ($this->statut) { dol_syslog(get_class($this)."::valid not in draft status", LOG_WARNING); return 0; } if (!((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->creer)) - || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate)))) - { + || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->shipping_advance->validate)))) { $this->error = 'Permission denied'; dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); return -1; @@ -695,8 +696,7 @@ class Expedition extends CommonObject $result = $soc->set_as_client(); // Define new ref - if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life - { + if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $numref = $this->getNextNumRef($soc); } else { $numref = "EXP".$this->id; @@ -715,15 +715,13 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::valid update expedition", LOG_DEBUG); $resql = $this->db->query($sql); - if (!$resql) - { + if (!$resql) { $this->error = $this->db->lasterror(); $error++; } // If stock increment is done on sending (recommanded choice) - if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) - { + if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -740,27 +738,25 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $cpt = $this->db->num_rows($resql); - for ($i = 0; $i < $cpt; $i++) - { + for ($i = 0; $i < $cpt; $i++) { $obj = $this->db->fetch_object($resql); - if (empty($obj->edbrowid)) - { + if (empty($obj->edbrowid)) { $qty = $obj->qty; } else { $qty = $obj->edbqty; } - if ($qty <= 0) continue; + if ($qty <= 0) { + continue; + } dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid); //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = dol_clone($this, 1); - if (empty($obj->edbrowid)) - { + if (empty($obj->edbrowid)) { // line without batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record. @@ -795,48 +791,45 @@ class Expedition extends CommonObject // Change status of order to "shipment in process" $ret = $this->setStatut(Commande::STATUS_SHIPMENTONPROCESS, $this->origin_id, $this->origin); - if (!$ret) - { + if (!$ret) { $error++; } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('SHIPPING_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 = 'expedition/sending/".$this->db->escape($this->newref)."'"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/sending/".$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($numref); $dirsource = $conf->expedition->dir_output.'/sending/'.$oldref; $dirdest = $conf->expedition->dir_output.'/sending/'.$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->expedition->dir_output.'/sending/'.$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; @@ -849,14 +842,12 @@ class Expedition extends CommonObject } // Set new ref and current status - if (!$error) - { + if (!$error) { $this->ref = $numref; $this->statut = self::STATUS_VALIDATED; } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -878,23 +869,24 @@ class Expedition extends CommonObject // phpcs:enable global $conf; - if ($conf->delivery_note->enabled) - { - if ($this->statut == self::STATUS_VALIDATED || $this->statut == self::STATUS_CLOSED) - { + if ($conf->delivery_note->enabled) { + if ($this->statut == self::STATUS_VALIDATED || $this->statut == self::STATUS_CLOSED) { // Expedition validee include_once DOL_DOCUMENT_ROOT.'/delivery/class/delivery.class.php'; $delivery = new Delivery($this->db); $result = $delivery->create_from_sending($user, $this->id); - if ($result > 0) - { + if ($result > 0) { return $result; } else { $this->error = $delivery->error; return $result; } - } else return 0; - } else return 0; + } else { + return 0; + } + } else { + return 0; + } } /** @@ -926,8 +918,7 @@ class Expedition extends CommonObject // Copy the rang of the order line to the expedition line $line->rang = $orderline->rang; - if (!empty($conf->stock->enabled) && !empty($orderline->fk_product)) - { + if (!empty($conf->stock->enabled) && !empty($orderline->fk_product)) { $fk_product = $orderline->fk_product; if (!($entrepot_id > 0) && empty($conf->global->STOCK_WAREHOUSE_NOT_REQUIRED_FOR_SHIPMENTS)) { @@ -967,15 +958,15 @@ class Expedition extends CommonObject } // If product need a batch number, we should not have called this function but addline_batch instead. - if (!empty($conf->productbatch->enabled) && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) - { + if (!empty($conf->productbatch->enabled) && !empty($orderline->fk_product) && !empty($orderline->product_tobatch)) { $this->error = 'ADDLINE_WAS_CALLED_INSTEAD_OF_ADDLINEBATCH'; return -4; } // extrafields - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used $line->array_options = $array_options; + } $this->lines[$num] = $line; } @@ -994,36 +985,30 @@ class Expedition extends CommonObject global $conf, $langs; $num = count($this->lines); - if ($dbatch['qty'] > 0) - { + if ($dbatch['qty'] > 0) { $line = new ExpeditionLigne($this->db); $tab = array(); - foreach ($dbatch['detail'] as $key=>$value) - { - if ($value['q'] > 0) - { + foreach ($dbatch['detail'] as $key => $value) { + if ($value['q'] > 0) { // $value['q']=qty to move // $value['id_batch']=id into llx_product_batch of record to move //var_dump($value); $linebatch = new ExpeditionLineBatch($this->db); $ret = $linebatch->fetchFromStock($value['id_batch']); // load serial, sellby, eatby - if ($ret < 0) - { + if ($ret < 0) { $this->error = $linebatch->error; return -1; } $linebatch->qty = $value['q']; $tab[] = $linebatch; - if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) - { + if ($conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT) { require_once DOL_DOCUMENT_ROOT.'/product/class/productbatch.class.php'; $prod_batch = new Productbatch($this->db); $prod_batch->fetch($value['id_batch']); - if ($prod_batch->qty < $linebatch->qty) - { + if ($prod_batch->qty < $linebatch->qty) { $langs->load("errors"); $this->errors[] = $langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product); dol_syslog(get_class($this)."::addline_batch error=Product ".$prod_batch->batch.": ".$this->errorsToString(), LOG_ERR); @@ -1042,8 +1027,9 @@ class Expedition extends CommonObject $line->detail_batch = $tab; // extrafields - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used $line->array_options = $array_options; + } //var_dump($line); $this->lines[$num] = $line; @@ -1065,25 +1051,63 @@ class Expedition extends CommonObject // Clean parameters - if (isset($this->ref)) $this->ref = trim($this->ref); - if (isset($this->entity)) $this->entity = (int) $this->entity; - if (isset($this->ref_customer)) $this->ref_customer = trim($this->ref_customer); - if (isset($this->socid)) $this->socid = (int) $this->socid; - if (isset($this->fk_user_author)) $this->fk_user_author = (int) $this->fk_user_author; - if (isset($this->fk_user_valid)) $this->fk_user_valid = (int) $this->fk_user_valid; - if (isset($this->fk_delivery_address)) $this->fk_delivery_address = (int) $this->fk_delivery_address; - if (isset($this->shipping_method_id)) $this->shipping_method_id = (int) $this->shipping_method_id; - if (isset($this->tracking_number)) $this->tracking_number = trim($this->tracking_number); - if (isset($this->statut)) $this->statut = (int) $this->statut; - if (isset($this->trueDepth)) $this->trueDepth = trim($this->trueDepth); - if (isset($this->trueWidth)) $this->trueWidth = trim($this->trueWidth); - if (isset($this->trueHeight)) $this->trueHeight = trim($this->trueHeight); - if (isset($this->size_units)) $this->size_units = trim($this->size_units); - if (isset($this->weight_units)) $this->weight_units = trim($this->weight_units); - if (isset($this->trueWeight)) $this->weight = trim($this->trueWeight); - if (isset($this->note_private)) $this->note_private = 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->ref)) { + $this->ref = trim($this->ref); + } + if (isset($this->entity)) { + $this->entity = (int) $this->entity; + } + if (isset($this->ref_customer)) { + $this->ref_customer = trim($this->ref_customer); + } + if (isset($this->socid)) { + $this->socid = (int) $this->socid; + } + if (isset($this->fk_user_author)) { + $this->fk_user_author = (int) $this->fk_user_author; + } + if (isset($this->fk_user_valid)) { + $this->fk_user_valid = (int) $this->fk_user_valid; + } + if (isset($this->fk_delivery_address)) { + $this->fk_delivery_address = (int) $this->fk_delivery_address; + } + if (isset($this->shipping_method_id)) { + $this->shipping_method_id = (int) $this->shipping_method_id; + } + if (isset($this->tracking_number)) { + $this->tracking_number = trim($this->tracking_number); + } + if (isset($this->statut)) { + $this->statut = (int) $this->statut; + } + if (isset($this->trueDepth)) { + $this->trueDepth = trim($this->trueDepth); + } + if (isset($this->trueWidth)) { + $this->trueWidth = trim($this->trueWidth); + } + if (isset($this->trueHeight)) { + $this->trueHeight = trim($this->trueHeight); + } + if (isset($this->size_units)) { + $this->size_units = trim($this->size_units); + } + if (isset($this->weight_units)) { + $this->weight_units = trim($this->weight_units); + } + if (isset($this->trueWeight)) { + $this->weight = trim($this->trueWeight); + } + if (isset($this->note_private)) { + $this->note_private = 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); + } @@ -1125,20 +1149,22 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::update", 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 && !$notrigger) { // Call trigger $result = $this->call_trigger('SHIPPING_MODIFY', $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); } @@ -1180,15 +1206,16 @@ class Expedition extends CommonObject if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('SHIPPING_CANCEL', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } // Stock control if (!$error && $conf->stock->enabled && (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) || - ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) - { + ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) { require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"; $langs->load("agenda"); @@ -1202,11 +1229,9 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::delete select details", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $cpt = $this->db->num_rows($resql); - for ($i = 0; $i < $cpt; $i++) - { + for ($i = 0; $i < $cpt; $i++) { dol_syslog(get_class($this)."::delete movement index ".$i); $obj = $this->db->fetch_object($resql); @@ -1215,11 +1240,9 @@ class Expedition extends CommonObject $mouvS->origin = null; // get lot/serial $lotArray = null; - if ($conf->productbatch->enabled) - { + if ($conf->productbatch->enabled) { $lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id); - if (!is_array($lotArray)) - { + if (!is_array($lotArray)) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } } @@ -1228,24 +1251,23 @@ class Expedition extends CommonObject // We increment stock of product (and sub-products) // We use warehouse selected for each line $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentCanceledInDolibarr", $this->ref)); // Price is set to 0, because we don't want to see WAP changed - if ($result < 0) - { + if ($result < 0) { $error++; $this->errors = $this->errors + $mouvS->errors; break; } } else { // We increment stock of batches // We use warehouse selected for each line - foreach ($lotArray as $lot) - { + foreach ($lotArray as $lot) { $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans("ShipmentCanceledInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch); // Price is set to 0, because we don't want to see WAP changed - if ($result < 0) - { + if ($result < 0) { $error++; $this->errors = $this->errors + $mouvS->errors; break; } } - if ($error) break; // break for loop incase of error + if ($error) { + break; // break for loop incase of error + } } } } else { @@ -1254,71 +1276,58 @@ class Expedition extends CommonObject } // delete batch expedition line - if (!$error && $conf->productbatch->enabled) - { - if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) - { + if (!$error && $conf->productbatch->enabled) { + if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } } - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet"; $sql .= " WHERE fk_expedition = ".$this->id; - if ($this->db->query($sql)) - { + if ($this->db->query($sql)) { // Delete linked object $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } // No delete expedition - if (!$error) - { + if (!$error) { $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."expedition"; $sql .= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) - { - if (!empty($this->origin) && $this->origin_id > 0) - { + if ($this->db->query($sql)) { + if (!empty($this->origin) && $this->origin_id > 0) { $this->fetch_origin(); $origin = $this->origin; - if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) // If order source of shipment is "shipment in progress" - { + if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) { // If order source of shipment is "shipment in progress" // Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress" $this->$origin->loadExpeditions(); //var_dump($this->$origin->expeditions);exit; - if (count($this->$origin->expeditions) <= 0) - { + if (count($this->$origin->expeditions) <= 0) { $this->$origin->setStatut(Commande::STATUS_VALIDATED); } } } - if (!$error) - { + if (!$error) { $this->db->commit(); // We delete PDFs $ref = dol_sanitizeFileName($this->ref); - if (!empty($conf->expedition->dir_output)) - { + if (!empty($conf->expedition->dir_output)) { $dir = $conf->expedition->dir_output.'/sending/'.$ref; $file = $dir.'/'.$ref.'.pdf'; - if (file_exists($file)) - { - if (!dol_delete_file($file)) - { + if (file_exists($file)) { + if (!dol_delete_file($file)) { return 0; } } - if (file_exists($dir)) - { - if (!dol_delete_dir_recursive($dir)) - { + if (file_exists($dir)) { + if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); return 0; } @@ -1373,8 +1382,7 @@ class Expedition extends CommonObject // Add a protection to refuse deleting if shipment has at least one delivery $this->fetchObjectLinked($this->id, 'shipping', 0, 'delivery'); // Get deliveries linked to this shipment - if (count($this->linkedObjectsIds) > 0) - { + if (count($this->linkedObjectsIds) > 0) { $this->error = 'ErrorThereIsSomeDeliveries'; $error++; } @@ -1382,15 +1390,16 @@ class Expedition extends CommonObject if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('SHIPPING_DELETE', $user); - if ($result < 0) { $error++; } + if ($result < 0) { + $error++; + } // End call triggers } // Stock control if (!$error && $conf->stock->enabled && (($conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > self::STATUS_DRAFT) || - ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) - { + ($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE && $this->statut == self::STATUS_CLOSED && $also_update_stock))) { require_once DOL_DOCUMENT_ROOT."/product/stock/class/mouvementstock.class.php"; $langs->load("agenda"); @@ -1404,11 +1413,9 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::delete select details", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $cpt = $this->db->num_rows($resql); - for ($i = 0; $i < $cpt; $i++) - { + for ($i = 0; $i < $cpt; $i++) { dol_syslog(get_class($this)."::delete movement index ".$i); $obj = $this->db->fetch_object($resql); @@ -1417,11 +1424,9 @@ class Expedition extends CommonObject $mouvS->origin = null; // get lot/serial $lotArray = null; - if ($conf->productbatch->enabled) - { + if ($conf->productbatch->enabled) { $lotArray = ExpeditionLineBatch::fetchAll($this->db, $obj->expeditiondet_id); - if (!is_array($lotArray)) - { + if (!is_array($lotArray)) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } } @@ -1430,24 +1435,23 @@ class Expedition extends CommonObject // We increment stock of product (and sub-products) // We use warehouse selected for each line $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref)); // Price is set to 0, because we don't want to see WAP changed - if ($result < 0) - { + if ($result < 0) { $error++; $this->errors = $this->errors + $mouvS->errors; break; } } else { // We increment stock of batches // We use warehouse selected for each line - foreach ($lotArray as $lot) - { + foreach ($lotArray as $lot) { $result = $mouvS->reception($user, $obj->fk_product, $obj->fk_entrepot, $lot->qty, 0, $langs->trans("ShipmentDeletedInDolibarr", $this->ref), $lot->eatby, $lot->sellby, $lot->batch); // Price is set to 0, because we don't want to see WAP changed - if ($result < 0) - { + if ($result < 0) { $error++; $this->errors = $this->errors + $mouvS->errors; break; } } - if ($error) break; // break for loop incase of error + if ($error) { + break; // break for loop incase of error + } } } } else { @@ -1456,16 +1460,13 @@ class Expedition extends CommonObject } // delete batch expedition line - if (!$error && $conf->productbatch->enabled) - { - if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) - { + if (!$error && $conf->productbatch->enabled) { + if (ExpeditionLineBatch::deletefromexp($this->db, $this->id) < 0) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); } } - if (!$error) - { + if (!$error) { $main = MAIN_DB_PREFIX.'expeditiondet'; $ef = $main."_extrafields"; $sqlef = "DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_expedition = ".$this->id.")"; @@ -1473,41 +1474,38 @@ class Expedition extends CommonObject $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet"; $sql .= " WHERE fk_expedition = ".$this->id; - if ($this->db->query($sqlef) && $this->db->query($sql)) - { + if ($this->db->query($sqlef) && $this->db->query($sql)) { // Delete linked object $res = $this->deleteObjectLinked(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } // delete extrafields $res = $this->deleteExtraFields(); - if ($res < 0) $error++; + if ($res < 0) { + $error++; + } - if (!$error) - { + if (!$error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."expedition"; $sql .= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) - { - if (!empty($this->origin) && $this->origin_id > 0) - { + if ($this->db->query($sql)) { + if (!empty($this->origin) && $this->origin_id > 0) { $this->fetch_origin(); $origin = $this->origin; - if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) // If order source of shipment is "shipment in progress" - { + if ($this->$origin->statut == Commande::STATUS_SHIPMENTONPROCESS) { // If order source of shipment is "shipment in progress" // Check if there is no more shipment. If not, we can move back status of order to "validated" instead of "shipment in progress" $this->$origin->loadExpeditions(); //var_dump($this->$origin->expeditions);exit; - if (count($this->$origin->expeditions) <= 0) - { + if (count($this->$origin->expeditions) <= 0) { $this->$origin->setStatut(Commande::STATUS_VALIDATED); } } } - if (!$error) - { + if (!$error) { $this->db->commit(); // Delete record into ECM index (Note that delete is also done when deleting files with the dol_delete_dir_recursive @@ -1515,21 +1513,16 @@ class Expedition extends CommonObject // We delete PDFs $ref = dol_sanitizeFileName($this->ref); - if (!empty($conf->expedition->dir_output)) - { + if (!empty($conf->expedition->dir_output)) { $dir = $conf->expedition->dir_output.'/sending/'.$ref; $file = $dir.'/'.$ref.'.pdf'; - if (file_exists($file)) - { - if (!dol_delete_file($file)) - { + if (file_exists($file)) { + if (!dol_delete_file($file)) { return 0; } } - if (file_exists($dir)) - { - if (!dol_delete_dir_recursive($dir)) - { + if (file_exists($dir)) { + if (!dol_delete_dir_recursive($dir)) { $this->error = $langs->trans("ErrorCanNotDeleteDir", $dir); return 0; } @@ -1590,8 +1583,7 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; $num = $this->db->num_rows($resql); @@ -1607,8 +1599,7 @@ class Expedition extends CommonObject $line = new ExpeditionLigne($this->db); - while ($i < $num) - { + while ($i < $num) { $obj = $this->db->fetch_object($resql); if ($originline == $obj->fk_origin_line) { @@ -1699,21 +1690,17 @@ class Expedition extends CommonObject $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - if ($originline != $obj->fk_origin_line) - { + if ($originline != $obj->fk_origin_line) { $line->detail_batch = array(); } // Detail of batch - if (!empty($conf->productbatch->enabled) && $obj->line_id > 0 && $obj->product_tobatch > 0) - { + if (!empty($conf->productbatch->enabled) && $obj->line_id > 0 && $obj->product_tobatch > 0) { require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; $newdetailbatch = ExpeditionLineBatch::fetchAll($this->db, $obj->line_id, $obj->fk_product); - if (is_array($newdetailbatch)) - { - if ($originline != $obj->fk_origin_line) - { + if (is_array($newdetailbatch)) { + if ($originline != $obj->fk_origin_line) { $line->detail_batch = $newdetailbatch; } else { $line->detail_batch = array_merge($line->detail_batch, $newdetailbatch); @@ -1721,8 +1708,7 @@ class Expedition extends CommonObject } } - if ($originline != $obj->fk_origin_line) - { + if ($originline != $obj->fk_origin_line) { $this->lines[$lineindex] = $line; $lineindex++; } else { @@ -1755,8 +1741,7 @@ class Expedition extends CommonObject { global $user; - if ($this->statut == self::STATUS_DRAFT) - { + if ($this->statut == self::STATUS_DRAFT) { $this->db->begin(); $line = new ExpeditionLigne($this->db); @@ -1764,8 +1749,7 @@ class Expedition extends CommonObject // For triggers $line->fetch($lineid); - if ($line->delete($user) > 0) - { + if ($line->delete($user) > 0) { //$this->update_price(1); $this->db->commit(); @@ -1803,21 +1787,24 @@ class Expedition extends CommonObject $url = DOL_URL_ROOT.'/expedition/card.php?id='.$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'; + } } $linkclose = ''; - if (empty($notooltip)) - { - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { + if (empty($notooltip)) { + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $label = $langs->trans("Shipment"); $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } @@ -1830,8 +1817,12 @@ class Expedition extends CommonObject $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; return $result; @@ -1865,9 +1856,15 @@ class Expedition extends CommonObject $labelStatusShort = $langs->trans($this->statutshorts[$status]); $statusType = 'status'.$status; - if ($status == self::STATUS_VALIDATED) $statusType = 'status4'; - if ($status == self::STATUS_CLOSED) $statusType = 'status6'; - if ($status == self::STATUS_CANCELED) $statusType = 'status9'; + if ($status == self::STATUS_VALIDATED) { + $statusType = 'status4'; + } + if ($status == self::STATUS_CLOSED) { + $statusType = 'status6'; + } + if ($status == self::STATUS_CANCELED) { + $statusType = 'status9'; + } return dolGetStatus($labelStatus, $labelStatusShort, '', $statusType, $mode); } @@ -1894,12 +1891,10 @@ class Expedition extends CommonObject $sql .= " FROM ".MAIN_DB_PREFIX."product"; $sql .= " WHERE entity IN (".getEntity('product').")"; $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]; @@ -1936,8 +1931,7 @@ class Expedition extends CommonObject $nbp = 5; $xnbp = 0; - while ($xnbp < $nbp) - { + while ($xnbp < $nbp) { $line = new ExpeditionLigne($this->db); $line->desc = $langs->trans("Description")." ".$xnbp; $line->libelle = $langs->trans("Description")." ".$xnbp; // deprecated @@ -1976,16 +1970,14 @@ class Expedition extends CommonObject */ public function setDeliveryDate($user, $delivery_date) { - if ($user->rights->expedition->creer) - { + if ($user->rights->expedition->creer) { $sql = "UPDATE ".MAIN_DB_PREFIX."expedition"; $sql .= " SET date_delivery = ".($delivery_date ? "'".$this->db->idate($delivery_date)."'" : 'null'); $sql .= " WHERE rowid = ".$this->id; dol_syslog(get_class($this)."::setDeliveryDate", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->date_delivery = $delivery_date; return 1; } else { @@ -2015,10 +2007,8 @@ class Expedition extends CommonObject $sql .= " ORDER BY em.libelle ASC"; $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $label = $langs->trans('SendingMethod'.$obj->code); $this->meths[$obj->rowid] = ($label != 'SendingMethod'.$obj->code ? $label : $obj->label); } @@ -2042,13 +2032,13 @@ class Expedition extends CommonObject $sql = "SELECT em.rowid, em.code, em.libelle as label, em.description, em.tracking, em.active"; $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; - if ($id != '') $sql .= " WHERE em.rowid=".$id; + if ($id != '') { + $sql .= " WHERE em.rowid=".$id; + } $resql = $this->db->query($sql); - if ($resql) - { - while ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + while ($obj = $this->db->fetch_object($resql)) { $this->listmeths[$i]['rowid'] = $obj->rowid; $this->listmeths[$i]['code'] = $obj->code; $label = $langs->trans('SendingMethod'.$obj->code); @@ -2072,8 +2062,7 @@ class Expedition extends CommonObject public function update_delivery_method($id = '') { // phpcs:enable - if ($id == '') - { + if ($id == '') { $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_shipment_mode (code, libelle, description, tracking)"; $sql .= " VALUES ('".$this->db->escape($this->update['code'])."','".$this->db->escape($this->update['libelle'])."','".$this->db->escape($this->update['description'])."','".$this->db->escape($this->update['tracking'])."')"; $resql = $this->db->query($sql); @@ -2086,7 +2075,9 @@ class Expedition extends CommonObject $sql .= " WHERE rowid=".$id; $resql = $this->db->query($sql); } - if ($resql < 0) dol_print_error($this->db, ''); + if ($resql < 0) { + dol_print_error($this->db, ''); + } } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps @@ -2131,24 +2122,20 @@ class Expedition extends CommonObject */ public function getUrlTrackingStatus($value = '') { - if (!empty($this->shipping_method_id)) - { + if (!empty($this->shipping_method_id)) { $sql = "SELECT em.code, em.tracking"; $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; $sql .= " WHERE em.rowid = ".$this->shipping_method_id; $resql = $this->db->query($sql); - if ($resql) - { - if ($obj = $this->db->fetch_object($resql)) - { + if ($resql) { + if ($obj = $this->db->fetch_object($resql)) { $tracking = $obj->tracking; } } } - if (!empty($tracking) && !empty($value)) - { + if (!empty($tracking) && !empty($value)) { $url = str_replace('{TRACKID}', $value, $tracking); $this->tracking_url = sprintf(''.($value ? $value : 'url').'', $url, $url); } else { @@ -2168,8 +2155,7 @@ class Expedition extends CommonObject $error = 0; // Protection. This avoid to move stock later when we should not - if ($this->statut == self::STATUS_CLOSED) - { + if ($this->statut == self::STATUS_CLOSED) { return 0; } @@ -2179,31 +2165,26 @@ class Expedition extends CommonObject $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { // Set order billed if 100% of order is shipped (qty in shipment lines match qty in order lines) - if ($this->origin == 'commande' && $this->origin_id > 0) - { + if ($this->origin == 'commande' && $this->origin_id > 0) { $order = new Commande($this->db); $order->fetch($this->origin_id); $order->loadExpeditions(self::STATUS_CLOSED); // Fill $order->expeditions = array(orderlineid => qty) $shipments_match_order = 1; - foreach ($order->lines as $line) - { + foreach ($order->lines as $line) { $lineid = $line->id; $qty = $line->qty; - if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty) - { + if (($line->product_type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && $order->expeditions[$lineid] != $qty) { $shipments_match_order = 0; $text = 'Qty for order line id '.$lineid.' is '.$qty.'. However in the shipments with status Expedition::STATUS_CLOSED='.self::STATUS_CLOSED.' we have qty = '.$order->expeditions[$lineid].', so we can t close order'; dol_syslog($text); break; } } - if ($shipments_match_order) - { + if ($shipments_match_order) { dol_syslog("Qty for the ".count($order->lines)." lines of order have same value for shipments with status Expedition::STATUS_CLOSED=".self::STATUS_CLOSED.', so we close order'); $order->cloture($user); } @@ -2213,8 +2194,7 @@ class Expedition extends CommonObject // If stock increment is done on closing - if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) - { + if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -2232,26 +2212,24 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $cpt = $this->db->num_rows($resql); - for ($i = 0; $i < $cpt; $i++) - { + for ($i = 0; $i < $cpt; $i++) { $obj = $this->db->fetch_object($resql); - if (empty($obj->edbrowid)) - { + if (empty($obj->edbrowid)) { $qty = $obj->qty; } else { $qty = $obj->edbqty; } - if ($qty <= 0) continue; + if ($qty <= 0) { + continue; + } dol_syslog(get_class($this)."::valid movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid); $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; - if (empty($obj->edbrowid)) - { + if (empty($obj->edbrowid)) { // line without batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record @@ -2280,8 +2258,7 @@ class Expedition extends CommonObject } // Call trigger - if (!$error) - { + if (!$error) { $result = $this->call_trigger('SHIPPING_CLOSED', $user); if ($result < 0) { $error++; @@ -2292,8 +2269,7 @@ class Expedition extends CommonObject $error++; } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -2334,8 +2310,7 @@ class Expedition extends CommonObject $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->statut = self::STATUS_CLOSED; $this->billed = 1; @@ -2372,8 +2347,7 @@ class Expedition extends CommonObject $error = 0; // Protection. This avoid to move stock later when we should not - if ($this->statut == self::STATUS_VALIDATED) - { + if ($this->statut == self::STATUS_VALIDATED) { return 0; } @@ -2385,14 +2359,12 @@ class Expedition extends CommonObject $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $this->statut = self::STATUS_VALIDATED; $this->billed = 0; // If stock increment is done on closing - if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) - { + if (!$error && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE)) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -2410,27 +2382,25 @@ class Expedition extends CommonObject dol_syslog(get_class($this)."::valid select details", LOG_DEBUG); $resql = $this->db->query($sql); - if ($resql) - { + if ($resql) { $cpt = $this->db->num_rows($resql); - for ($i = 0; $i < $cpt; $i++) - { + for ($i = 0; $i < $cpt; $i++) { $obj = $this->db->fetch_object($resql); - if (empty($obj->edbrowid)) - { + if (empty($obj->edbrowid)) { $qty = $obj->qty; } else { $qty = $obj->edbqty; } - if ($qty <= 0) continue; + if ($qty <= 0) { + continue; + } dol_syslog(get_class($this)."::reopen expedition movement index ".$i." ed.rowid=".$obj->rowid." edb.rowid=".$obj->edbrowid); //var_dump($this->lines[$i]); $mouvS = new MouvementStock($this->db); $mouvS->origin = &$this; - if (empty($obj->edbrowid)) - { + if (empty($obj->edbrowid)) { // line without batch detail // We decrement stock of product (and sub-products) -> update table llx_product_stock (key of this table is fk_product+fk_entrepot) and add a movement record @@ -2470,8 +2440,7 @@ class Expedition extends CommonObject $this->errors[] = $this->db->lasterror(); } - if (!$error) - { + if (!$error) { $this->db->commit(); return 1; } else { @@ -2715,8 +2684,7 @@ class ExpeditionLigne extends CommonObjectLine $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as ed'; $sql .= ' WHERE ed.rowid = '.$rowid; $result = $this->db->query($sql); - if ($result) - { + if ($result) { $objp = $this->db->fetch_object($result); $this->id = $objp->rowid; $this->fk_expedition = $objp->fk_expedition; @@ -2749,20 +2717,20 @@ class ExpeditionLigne extends CommonObjectLine $error = 0; // Check parameters - if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty)) - { + if (empty($this->fk_expedition) || empty($this->fk_origin_line) || !is_numeric($this->qty)) { $this->error = 'ErrorMandatoryParametersNotProvided'; return -1; } $this->db->begin(); - if (empty($this->rang)) $this->rang = 0; + if (empty($this->rang)) { + $this->rang = 0; + } // Rank to use $ranktouse = $this->rang; - if ($ranktouse == -1) - { + if ($ranktouse == -1) { $rangmax = $this->line_max($this->fk_expedition); $ranktouse = $rangmax + 1; } @@ -2783,25 +2751,20 @@ class ExpeditionLigne extends CommonObjectLine 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."expeditiondet"); - 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('LINESHIPPING_INSERT', $user); - if ($result < 0) - { + if ($result < 0) { $error++; } // End call triggers @@ -2812,8 +2775,7 @@ class ExpeditionLigne extends CommonObjectLine return $this->id; } - 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); } @@ -2841,13 +2803,11 @@ class ExpeditionLigne extends CommonObjectLine $this->db->begin(); // delete batch expedition line - if ($conf->productbatch->enabled) - { + if ($conf->productbatch->enabled) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_batch"; $sql .= " WHERE fk_expeditiondet = ".$this->id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $this->errors[] = $this->db->lasterror()." - sql=$sql"; $error++; } @@ -2856,24 +2816,19 @@ class ExpeditionLigne extends CommonObjectLine $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet"; $sql .= " WHERE rowid = ".$this->id; - if (!$error && $this->db->query($sql)) - { + if (!$error && $this->db->query($sql)) { // Remove extrafields - if (!$error) - { + if (!$error) { $result = $this->deleteExtraFields(); - if ($result < 0) - { + if ($result < 0) { $this->errors[] = $this->error; $error++; } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('LINESHIPPING_DELETE', $user); - if ($result < 0) - { + if ($result < 0) { $this->errors[] = $this->error; $error++; } @@ -2888,8 +2843,7 @@ class ExpeditionLigne extends CommonObjectLine $this->db->commit(); return 1; } else { - 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); } @@ -2916,16 +2870,16 @@ class ExpeditionLigne extends CommonObjectLine $this->db->begin(); // Clean parameters - if (empty($this->qty)) $this->qty = 0; + if (empty($this->qty)) { + $this->qty = 0; + } $qty = price2num($this->qty); $remainingQty = 0; $batch = null; $batch_id = null; $expedition_batch_id = null; - if (is_array($this->detail_batch)) // array of ExpeditionLineBatch - { - if (count($this->detail_batch) > 1) - { + if (is_array($this->detail_batch)) { // array of ExpeditionLineBatch + if (count($this->detail_batch) > 1) { dol_syslog(get_class($this).'::update only possible for one batch', LOG_ERR); $this->errors[] = 'ErrorBadParameters'; $error++; @@ -2933,21 +2887,18 @@ class ExpeditionLigne extends CommonObjectLine $batch = $this->detail_batch[0]->batch; $batch_id = $this->detail_batch[0]->fk_origin_stock; $expedition_batch_id = $this->detail_batch[0]->id; - if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) - { + if ($this->entrepot_id != $this->detail_batch[0]->entrepot_id) { dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR); $this->errors[] = 'ErrorBadParameters'; $error++; } $qty = price2num($this->detail_batch[0]->qty); } - } elseif (!empty($this->detail_batch)) - { + } elseif (!empty($this->detail_batch)) { $batch = $this->detail_batch->batch; $batch_id = $this->detail_batch->fk_origin_stock; $expedition_batch_id = $this->detail_batch->id; - if ($this->entrepot_id != $this->detail_batch->entrepot_id) - { + if ($this->entrepot_id != $this->detail_batch->entrepot_id) { dol_syslog(get_class($this).'::update only possible for batch of same warehouse', LOG_ERR); $this->errors[] = 'ErrorBadParameters'; $error++; @@ -2956,8 +2907,7 @@ class ExpeditionLigne extends CommonObjectLine } // check parameters - if (!isset($this->id) || !isset($this->entrepot_id)) - { + if (!isset($this->id) || !isset($this->entrepot_id)) { dol_syslog(get_class($this).'::update missing line id and/or warehouse id', LOG_ERR); $this->errors[] = 'ErrorMandatoryParametersNotProvided'; $error++; @@ -2966,8 +2916,7 @@ class ExpeditionLigne extends CommonObjectLine // update lot - if (!empty($batch) && $conf->productbatch->enabled) - { + if (!empty($batch) && $conf->productbatch->enabled) { dol_syslog(get_class($this)."::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch"); if (empty($batch_id) || empty($this->fk_product)) { @@ -2978,16 +2927,13 @@ class ExpeditionLigne extends CommonObjectLine // fetch remaining lot qty require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php'; - if (!$error && ($lotArray = ExpeditionLineBatch::fetchAll($this->db, $this->id)) < 0) - { + if (!$error && ($lotArray = ExpeditionLineBatch::fetchAll($this->db, $this->id)) < 0) { $this->errors[] = $this->db->lasterror()." - ExpeditionLineBatch::fetchAll"; $error++; } else { // caculate new total line qty - foreach ($lotArray as $lot) - { - if ($expedition_batch_id != $lot->id) - { + foreach ($lotArray as $lot) { + if ($expedition_batch_id != $lot->id) { $remainingQty += $lot->qty; } } @@ -2998,29 +2944,24 @@ class ExpeditionLigne extends CommonObjectLine // fetch from product_lot require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; $lot = new Productlot($this->db); - if ($lot->fetch(0, $this->fk_product, $batch) < 0) - { + if ($lot->fetch(0, $this->fk_product, $batch) < 0) { $this->errors[] = $lot->errors; $error++; } - if (!$error && !empty($expedition_batch_id)) - { + if (!$error && !empty($expedition_batch_id)) { // delete lot expedition line $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet_batch"; $sql .= " WHERE fk_expeditiondet = ".$this->id; $sql .= " AND rowid = ".$expedition_batch_id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $this->errors[] = $this->db->lasterror()." - sql=$sql"; $error++; } } - if (!$error && $this->detail_batch->qty > 0) - { + if (!$error && $this->detail_batch->qty > 0) { // create lot expedition line - if (isset($lot->id)) - { + if (isset($lot->id)) { $shipmentLot = new ExpeditionLineBatch($this->db); $shipmentLot->batch = $lot->batch; $shipmentLot->eatby = $lot->eatby; @@ -3028,8 +2969,7 @@ class ExpeditionLigne extends CommonObjectLine $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id; $shipmentLot->qty = $this->detail_batch->qty; $shipmentLot->fk_origin_stock = $batch_id; - if ($shipmentLot->create($this->id) < 0) - { + if ($shipmentLot->create($this->id) < 0) { $this->errors[] = $shipmentLot->errors; $error++; } @@ -3037,40 +2977,33 @@ class ExpeditionLigne extends CommonObjectLine } } } - if (!$error) - { + if (!$error) { // update line $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql .= " fk_entrepot = ".($this->entrepot_id > 0 ? $this->entrepot_id : 'null'); $sql .= " , qty = ".$qty; $sql .= " WHERE rowid = ".$this->id; - if (!$this->db->query($sql)) - { + if (!$this->db->query($sql)) { $this->errors[] = $this->db->lasterror()." - sql=$sql"; $error++; } } - if (!$error) - { - if (!$error) - { + if (!$error) { + if (!$error) { $result = $this->insertExtraFields(); - if ($result < 0) - { + if ($result < 0) { $this->errors[] = $this->error; $error++; } } } - if (!$error && !$notrigger) - { + if (!$error && !$notrigger) { // Call trigger $result = $this->call_trigger('LINESHIPPING_UPDATE', $user); - if ($result < 0) - { + if ($result < 0) { $this->errors[] = $this->error; $error++; } @@ -3080,8 +3013,7 @@ class ExpeditionLigne extends CommonObjectLine $this->db->commit(); return 1; } else { - foreach ($this->errors as $errmsg) - { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } diff --git a/htdocs/expedition/class/expeditionbatch.class.php b/htdocs/expedition/class/expeditionbatch.class.php index 637f9dd749c..f97d6b87a1b 100644 --- a/htdocs/expedition/class/expeditionbatch.class.php +++ b/htdocs/expedition/class/expeditionbatch.class.php @@ -75,10 +75,8 @@ class ExpeditionLineBatch extends CommonObject 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->sellby = $this->db->jdate($obj->sellby); @@ -126,16 +124,16 @@ class ExpeditionLineBatch extends CommonObject 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.self::$_table_element); $this->fk_expeditiondet = $id_line_expdet; return $this->id; } else { - foreach ($this->errors as $errmsg) - { + foreach ($this->errors as $errmsg) { dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); $this->error .= ($this->error ? ', '.$errmsg : $errmsg); } @@ -159,8 +157,7 @@ class ExpeditionLineBatch extends CommonObject $sql .= " WHERE fk_expeditiondet in (SELECT rowid FROM ".MAIN_DB_PREFIX."expeditiondet WHERE fk_expedition=".$id_expedition.")"; dol_syslog(__METHOD__, LOG_DEBUG); - if ($db->query($sql)) - { + if ($db->query($sql)) { return 1; } else { return -1; @@ -185,27 +182,23 @@ class ExpeditionLineBatch extends CommonObject $sql .= " eb.batch,"; $sql .= " eb.qty,"; $sql .= " eb.fk_origin_stock"; - if ($fk_product > 0) - { + if ($fk_product > 0) { $sql .= ", pl.sellby"; $sql .= ", pl.eatby"; } $sql .= " FROM ".MAIN_DB_PREFIX.self::$_table_element." as eb"; - if ($fk_product > 0) - { + if ($fk_product > 0) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lot as pl ON pl.batch = eb.batch AND pl.fk_product = ".$fk_product; } $sql .= " WHERE fk_expeditiondet=".(int) $id_line_expdet; dol_syslog(__METHOD__."", LOG_DEBUG); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; $ret = array(); - while ($i < $num) - { + while ($i < $num) { $tmp = new self($db); $obj = $db->fetch_object($resql); diff --git a/htdocs/expedition/class/expeditionstats.class.php b/htdocs/expedition/class/expeditionstats.class.php index 49d37179eda..50382cef164 100644 --- a/htdocs/expedition/class/expeditionstats.class.php +++ b/htdocs/expedition/class/expeditionstats.class.php @@ -73,12 +73,15 @@ class ExpeditionStats extends Stats //$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity; $this->where .= " AND c.entity = ".$conf->entity; - if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; - if ($this->socid) - { + if (!$user->rights->societe->client->voir && !$this->socid) { + $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".$user->id; + } + if ($this->socid) { $this->where .= " AND c.fk_soc = ".$this->socid; } - if ($this->userid > 0) $this->where .= ' AND c.fk_user_author = '.$this->userid; + if ($this->userid > 0) { + $this->where .= ' AND c.fk_user_author = '.$this->userid; + } } /** @@ -94,7 +97,9 @@ class ExpeditionStats extends Stats $sql = "SELECT date_format(c.date_valid,'%m') as dm, COUNT(*) as nb"; $sql .= " FROM ".$this->from; - if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$this->socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE c.date_valid BETWEEN '".$this->db->idate(dol_get_first_day($year))."' AND '".$this->db->idate(dol_get_last_day($year))."'"; $sql .= " AND ".$this->where; $sql .= " GROUP BY dm"; @@ -116,7 +121,9 @@ class ExpeditionStats extends Stats $sql = "SELECT date_format(c.date_valid,'%Y') as dm, COUNT(*) as nb, SUM(c.".$this->field.")"; $sql .= " FROM ".$this->from; - if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$this->socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE ".$this->where; $sql .= " GROUP BY dm"; $sql .= $this->db->order('dm', 'DESC'); @@ -135,7 +142,9 @@ class ExpeditionStats extends Stats $sql = "SELECT date_format(c.date_valid,'%Y') as year, COUNT(*) as nb, SUM(c.".$this->field.") as total, AVG(".$this->field.") as avg"; $sql .= " FROM ".$this->from; - if (!$user->rights->societe->client->voir && !$this->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$this->socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + } $sql .= " WHERE ".$this->where; $sql .= " GROUP BY year"; $sql .= $this->db->order('year', 'DESC'); diff --git a/htdocs/expedition/contact.php b/htdocs/expedition/contact.php index d15e267b285..a096b2155ce 100644 --- a/htdocs/expedition/contact.php +++ b/htdocs/expedition/contact.php @@ -42,30 +42,28 @@ $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); // Security check -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expedition', $id, ''); $object = new Expedition($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $object->fetch($id, $ref); $object->fetch_thirdparty(); - if (!empty($object->origin)) - { + if (!empty($object->origin)) { $typeobject = $object->origin; $origin = $object->origin; $object->fetch_origin(); } // Linked documents - if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) - { + if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) { $objectsrc = new Commande($db); $objectsrc->fetch($object->$typeobject->id); } - if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) - { + if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) { $objectsrc = new Propal($db); $objectsrc->fetch($object->$typeobject->id); } @@ -76,22 +74,18 @@ if ($id > 0 || !empty($ref)) * Actions */ -if ($action == 'addcontact' && $user->rights->expedition->creer) -{ - if ($result > 0 && $id > 0) - { +if ($action == 'addcontact' && $user->rights->expedition->creer) { + if ($result > 0 && $id > 0) { $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type')); $result = $objectsrc->add_contact($contactid, $typeid, GETPOST("source", 'aZ09')); } - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { - if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { + if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $langs->load("errors"); $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); } else { @@ -100,21 +94,14 @@ if ($action == 'addcontact' && $user->rights->expedition->creer) } setEventMessages($mesg, $mesgs, 'errors'); } -} - -// bascule du statut d'un contact -elseif ($action == 'swapstatut' && $user->rights->expedition->creer) -{ +} elseif ($action == 'swapstatut' && $user->rights->expedition->creer) { + // bascule du statut d'un contact $result = $objectsrc->swapContactStatus(GETPOST('ligne')); -} - -// Efface un contact -elseif ($action == 'deletecontact' && $user->rights->expedition->creer) -{ +} elseif ($action == 'deletecontact' && $user->rights->expedition->creer) { + // Efface un contact $result = $objectsrc->delete_contact(GETPOST("lineid")); - if ($result >= 0) - { + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } else { @@ -149,8 +136,7 @@ $userstatic = new User($db); /* */ /* *************************************************************************** */ -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $langs->trans("OrderCard"); $head = shipping_prepare_head($object); @@ -213,8 +199,7 @@ if ($id > 0 || !empty($ref)) print '
'.$formproduct->selectLotStock('', 'batchl'.$line_id.'_0', '', 1, 0, $lines[$i]->fk_product).'
- '.$langs->trans("NA").'
'.$lines[$i]->qty_shipped.''; - if ($lines[$i]->entrepot_id > 0) - { + if ($lines[$i]->entrepot_id > 0) { $entrepot = new Entrepot($db); $entrepot->fetch($lines[$i]->entrepot_id); print $entrepot->getNomUrl(1); - } elseif (count($lines[$i]->details_entrepot) > 1) - { + } elseif (count($lines[$i]->details_entrepot) > 1) { $detail = ''; - foreach ($lines[$i]->details_entrepot as $detail_entrepot) - { - if ($detail_entrepot->entrepot_id > 0) - { + foreach ($lines[$i]->details_entrepot as $detail_entrepot) { + if ($detail_entrepot->entrepot_id > 0) { $entrepot = new Entrepot($db); $entrepot->fetch($detail_entrepot->entrepot_id); $detail .= $langs->trans("DetailWarehouseFormat", $entrepot->libelle, $detail_entrepot->qty_shipped).'
'; @@ -2305,17 +2225,13 @@ if ($action == 'create') } // Batch number managment - if (!empty($conf->productbatch->enabled)) - { - if (isset($lines[$i]->detail_batch)) - { + if (!empty($conf->productbatch->enabled)) { + if (isset($lines[$i]->detail_batch)) { print ''; print '
'; - if ($lines[$i]->product_tobatch) - { + if ($lines[$i]->product_tobatch) { $detail = ''; - foreach ($lines[$i]->detail_batch as $dbatch) // $dbatch is instance of ExpeditionLineBatch - { + foreach ($lines[$i]->detail_batch as $dbatch) { // $dbatch is instance of ExpeditionLineBatch $detail .= $langs->trans("Batch").': '.$dbatch->batch; if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) { $detail .= ' - '.$langs->trans("SellByDate").': '.dol_print_date($dbatch->sellby, "day"); @@ -2339,27 +2255,31 @@ if ($action == 'create') // Weight print ''; - if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->weight * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "weight", $lines[$i]->weight_units); - else print ' '; + if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) { + print $lines[$i]->weight * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "weight", $lines[$i]->weight_units); + } else { + print ' '; + } print ''; - if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) print $lines[$i]->volume * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units); - else print ' '; + if ($lines[$i]->fk_product_type == Product::TYPE_PRODUCT) { + print $lines[$i]->volume * $lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units); + } else { + print ' '; + } print ''.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuringUnitString(0, "volume", $lines[$i]->volume_units).''; print '
'; print '
'; print '
'; print 'id.'">'.img_edit().''; @@ -2369,8 +2289,7 @@ if ($action == 'create') print '
'; // Linked documents - if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) - { + if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) { print '\n"; print ''; } - if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) - { + if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) { print ''; - if ($num) - { + if ($num) { $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); $shipment->id = $obj->rowid; @@ -123,7 +120,9 @@ if ($resql) print ''.$obj->name.''; print ''; print ''; $i++; } @@ -151,17 +150,22 @@ $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc"; +} $sql .= " WHERE e.entity IN (".getEntity('expedition').")"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND sc.fk_user = ".$user->id; +} $sql .= " AND e.fk_statut = ".Expedition::STATUS_VALIDATED; -if ($socid) $sql .= " AND c.fk_soc = ".$socid; +if ($socid) { + $sql .= " AND c.fk_soc = ".$socid; +} $sql .= " ORDER BY e.date_delivery DESC"; $sql .= $db->plimit($max, 0); $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); print '
'; @@ -175,11 +179,9 @@ if ($resql) print ''; print ''; - if ($num) - { + if ($num) { $i = 0; - while ($i < $num) - { + while ($i < $num) { $obj = $db->fetch_object($resql); $shipment->id = $obj->rowid; @@ -191,8 +193,7 @@ if ($resql) print ''; print '
'; print '
'; $objectsrc = new Commande($db); $objectsrc->fetch($object->$typeobject->id); @@ -224,8 +209,7 @@ if ($id > 0 || !empty($ref)) print "
'; $objectsrc = new Propal($db); $objectsrc->fetch($object->$typeobject->id); @@ -260,10 +244,11 @@ if ($id > 0 || !empty($ref)) // Contacts lines (modules that overwrite templates must declare this into descriptor) $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); $preselectedtypeofcontact = dol_getIdFromCode($db, 'SHIPPING', 'c_type_contact', 'code', 'rowid'); - foreach ($dirtpls as $reldir) - { + foreach ($dirtpls as $reldir) { $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); - if ($res) break; + if ($res) { + break; + } } } diff --git a/htdocs/expedition/document.php b/htdocs/expedition/document.php index 2b710e87dee..836b469cb77 100644 --- a/htdocs/expedition/document.php +++ b/htdocs/expedition/document.php @@ -46,8 +46,7 @@ $id = GETPOST('id', 'int'); $ref = GETPOST('ref'); // Security check -if ($user->socid) -{ +if ($user->socid) { $socid = $user->socid; } $result = restrictedArea($user, 'expedition', $id, ''); @@ -57,12 +56,18 @@ $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'alpha'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (!$sortorder) $sortorder = "ASC"; -if (!$sortfield) $sortfield = "name"; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "name"; +} $object = new Expedition($db); @@ -70,8 +75,7 @@ $object = new Expedition($db); /* * Actions */ -if ($object->fetch($id)) -{ +if ($object->fetch($id)) { $object->fetch_thirdparty(); $upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref); } diff --git a/htdocs/expedition/index.php b/htdocs/expedition/index.php index 4a84bfc6718..5ea3b923e91 100644 --- a/htdocs/expedition/index.php +++ b/htdocs/expedition/index.php @@ -54,8 +54,7 @@ print load_fiche_titre($langs->trans("SendingsArea"), '', 'dolly'); print '
'; -if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo -{ +if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is useless due to the global search combo print ''; print ''; print '
'; @@ -79,19 +78,19 @@ $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; -if (!$user->rights->societe->client->voir && !$socid) -{ +if (!$user->rights->societe->client->voir && !$socid) { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc"; $sql .= $clause." sc.fk_user = ".$user->id; $clause = " AND "; } $sql .= $clause." e.fk_statut = ".Expedition::STATUS_DRAFT; $sql .= " AND e.entity IN (".getEntity('expedition').")"; -if ($socid) $sql .= " AND c.fk_soc = ".$socid; +if ($socid) { + $sql .= " AND c.fk_soc = ".$socid; +} $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); print '
'; @@ -105,11 +104,9 @@ if ($resql) print ''; print '
'; - if ($obj->commande_id) print ''.$obj->commande_ref.''; + if ($obj->commande_id) { + print ''.$obj->commande_ref.''; + } print '
'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.''; - if ($obj->commande_id > 0) - { + if ($obj->commande_id > 0) { $orderstatic->id = $obj->commande_id; $orderstatic->ref = $obj->commande_ref; print $orderstatic->getNomUrl(1); @@ -209,7 +210,9 @@ if ($resql) } print "

"; $db->free($resql); -} else dol_print_error($db); +} else { + dol_print_error($db); +} /* * Open orders @@ -217,17 +220,22 @@ if ($resql) $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid"; $sql .= " FROM ".MAIN_DB_PREFIX."commande as c,"; $sql .= " ".MAIN_DB_PREFIX."societe as s"; -if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} $sql .= " WHERE c.fk_soc = s.rowid"; $sql .= " AND c.entity IN (".getEntity('order').")"; $sql .= " AND c.fk_statut IN (".Commande::STATUS_VALIDATED.", ".Commande::STATUS_ACCEPTED.")"; -if ($socid > 0) $sql .= " AND c.fk_soc = ".$socid; -if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +if ($socid > 0) { + $sql .= " AND c.fk_soc = ".$socid; +} +if (!$user->rights->societe->client->voir && !$socid) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; +} $sql .= " ORDER BY c.rowid ASC"; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $langs->load("orders"); $num = $db->num_rows($resql); @@ -243,11 +251,9 @@ if ($resql) print ''; print ''; - if ($num) - { + if ($num) { $i = 0; - while ($i < $num && $i < 10) - { + while ($i < $num && $i < 10) { $obj = $db->fetch_object($resql); $orderstatic->id = $obj->rowid; @@ -284,7 +290,9 @@ if ($resql) } print "
"; -} else dol_print_error($db); +} else { + dol_print_error($db); +} print ''; diff --git a/htdocs/expedition/list.php b/htdocs/expedition/list.php index a21ad170b09..f325fc286a5 100644 --- a/htdocs/expedition/list.php +++ b/htdocs/expedition/list.php @@ -49,7 +49,9 @@ $toselect = GETPOST('toselect', 'array'); // Security check $expeditionid = GETPOST('id', 'int'); -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, 'expedition', $expeditionid, ''); $search_ref_exp = GETPOST("search_ref_exp", 'alpha'); @@ -79,9 +81,15 @@ $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (!$sortfield) $sortfield = "e.ref"; -if (!$sortorder) $sortorder = "DESC"; -if (empty($page) || $page == -1 || (empty($toselect) && $massaction === '0')) { $page = 0; } // If $page is not defined, or '' or -1 +if (!$sortfield) { + $sortfield = "e.ref"; +} +if (!$sortorder) { + $sortorder = "DESC"; +} +if (empty($page) || $page == -1 || (empty($toselect) && $massaction === '0')) { + $page = 0; +} // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -109,7 +117,9 @@ $fieldstosearchall = array( 'e.note_public'=>'NotePublic', 'e.tracking_number'=>"TrackingNumber", ); -if (empty($user->socid)) $fieldstosearchall["e.note_private"] = "NotePrivate"; +if (empty($user->socid)) { + $fieldstosearchall["e.note_private"] = "NotePrivate"; +} $checkedtypetiers = 0; $arrayfields = array( @@ -144,18 +154,23 @@ $arrayfields = dol_sort_array($arrayfields, 'position'); */ $error = 0; -if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; } -if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; } +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; $massaction = ''; +} +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} $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'); +} include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Purge search criteria -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers -{ +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers $search_categ = ''; $search_user = ''; $search_sale = ''; @@ -182,8 +197,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $search_categ_cus = 0; } -if (empty($reshook)) -{ +if (empty($reshook)) { $objectclass = 'Expedition'; $objectlabel = 'Sendings'; $permissiontoread = $user->rights->expedition->lire; @@ -211,7 +225,9 @@ $helpurl = 'EN:Module_Shipments|FR:Module_Expéditions|ES:Módulo_Ex llxHeader('', $langs->trans('ListOfSendings'), $helpurl); $sql = 'SELECT'; -if ($sall || $search_product_category > 0 || $search_user > 0) $sql = 'SELECT DISTINCT'; +if ($sall || $search_product_category > 0 || $search_user > 0) { + $sql = 'SELECT DISTINCT'; +} $sql .= " e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.weight, e.weight_units, e.date_delivery as delivery_date, e.fk_statut, e.billed, e.tracking_number,"; $sql .= " l.date_delivery as date_reception,"; $sql .= " s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, "; @@ -219,24 +235,34 @@ $sql .= " typent.code as typent_code,"; $sql .= " state.code_departement as state_code, state.nom as state_name,"; $sql .= " e.date_creation as date_creation, e.tms as date_update,"; $sql .= " u.login"; -if ($search_categ_cus) $sql .= ", cc.fk_categorie, cc.fk_soc"; +if ($search_categ_cus) { + $sql .= ", cc.fk_categorie, cc.fk_soc"; +} // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { - foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) { + $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); + } } // Add fields from hooks $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."expedition as e"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)"; +if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) { + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (e.rowid = ef.fk_object)"; +} if ($sall || $search_product_category > 0) { $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'expeditiondet as ed ON e.rowid=ed.fk_expedition'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commandedet as pd ON pd.rowid=ed.fk_origin_line'; } -if ($search_product_category > 0) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; +if ($search_product_category > 0) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc"; -if (!empty($search_categ_cus)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ +if (!empty($search_categ_cus)) { + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)"; @@ -247,50 +273,91 @@ if ($search_user > 0) { // Get link to order to get the order id in eesource.fk $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as eesource ON eesource.fk_target = e.rowid AND eesource.targettype = 'shipping' AND eesource.sourcetype = 'commande'"; } // We'll need this table joined to the select in order to filter by sale -if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) { + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; +} if ($search_user > 0) { $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec"; $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql .= " WHERE e.entity IN (".getEntity('expedition').")"; -if ($search_product_category > 0) $sql .= " AND cp.fk_categorie = ".$search_product_category; -if ($socid > 0) $sql .= ' AND s.rowid = '.$socid; -if (!$user->rights->societe->client->voir && !$socid) // Internal user with no permission to see all -{ +if ($search_product_category > 0) { + $sql .= " AND cp.fk_categorie = ".$search_product_category; +} +if ($socid > 0) { + $sql .= ' AND s.rowid = '.$socid; +} +if (!$user->rights->societe->client->voir && !$socid) { // Internal user with no permission to see all $sql .= " AND e.fk_soc = sc.fk_soc"; $sql .= " AND sc.fk_user = ".$user->id; } -if ($socid) -{ +if ($socid) { $sql .= " AND e.fk_soc = ".$socid; } if ($search_status <> '' && $search_status >= 0) { $sql .= " AND e.fk_statut = ".$search_status; } -if ($search_ref_customer != '') $sql .= natural_search('e.ref_customer', $search_ref_customer); -if ($search_billed != '' && $search_billed >= 0) $sql .= ' AND e.billed = '.$search_billed; -if ($search_town) $sql .= natural_search('s.town', $search_town); -if ($search_zip) $sql .= natural_search("s.zip", $search_zip); -if ($search_state) $sql .= natural_search("state.nom", $search_state); -if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; -if ($search_tracking) $sql .= natural_search("e.tracking_number", $search_tracking); -if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; -if ($search_sale > 0) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale; -if ($search_user > 0) -{ +if ($search_ref_customer != '') { + $sql .= natural_search('e.ref_customer', $search_ref_customer); +} +if ($search_billed != '' && $search_billed >= 0) { + $sql .= ' AND e.billed = '.$search_billed; +} +if ($search_town) { + $sql .= natural_search('s.town', $search_town); +} +if ($search_zip) { + $sql .= natural_search("s.zip", $search_zip); +} +if ($search_state) { + $sql .= natural_search("state.nom", $search_state); +} +if ($search_country) { + $sql .= " AND s.fk_pays IN (".$search_country.')'; +} +if ($search_tracking) { + $sql .= natural_search("e.tracking_number", $search_tracking); +} +if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { + $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; +} +if ($search_sale > 0) { + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$search_sale; +} +if ($search_user > 0) { // The contact on a shipment is also the contact of the order. $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = eesource.fk_source AND ec.fk_socpeople = ".$db->escape($search_user); } -if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp); -if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv); -if ($search_company) $sql .= natural_search('s.nom', $search_company); -if ($search_datedelivery_start) $sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'"; -if ($search_datedelivery_end) $sql .= " AND e.date_delivery <= '".$db->idate($search_datedelivery_end)."'"; -if ($search_datereceipt_start) $sql .= " AND l.date_delivery >= '".$db->idate($search_datereceipt_start)."'"; -if ($search_datereceipt_end) $sql .= " AND l.date_delivery <= '".$db->idate($search_datereceipt_end)."'"; -if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall); -if ($search_categ_cus > 0) $sql .= " AND cc.fk_categorie = ".$db->escape($search_categ_cus); -if ($search_categ_cus == -2) $sql .= " AND cc.fk_categorie IS NULL"; +if ($search_ref_exp) { + $sql .= natural_search('e.ref', $search_ref_exp); +} +if ($search_ref_liv) { + $sql .= natural_search('l.ref', $search_ref_liv); +} +if ($search_company) { + $sql .= natural_search('s.nom', $search_company); +} +if ($search_datedelivery_start) { + $sql .= " AND e.date_delivery >= '".$db->idate($search_datedelivery_start)."'"; +} +if ($search_datedelivery_end) { + $sql .= " AND e.date_delivery <= '".$db->idate($search_datedelivery_end)."'"; +} +if ($search_datereceipt_start) { + $sql .= " AND l.date_delivery >= '".$db->idate($search_datereceipt_start)."'"; +} +if ($search_datereceipt_end) { + $sql .= " AND l.date_delivery <= '".$db->idate($search_datereceipt_end)."'"; +} +if ($sall) { + $sql .= natural_search(array_keys($fieldstosearchall), $sall); +} +if ($search_categ_cus > 0) { + $sql .= " AND cc.fk_categorie = ".$db->escape($search_categ_cus); +} +if ($search_categ_cus == -2) { + $sql .= " AND cc.fk_categorie IS NULL"; +} // Add where from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php'; @@ -303,12 +370,10 @@ $sql .= $hookmanager->resPrint; $sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -318,8 +383,7 @@ $sql .= $db->plimit($limit + 1, $offset); //print $sql; $resql = $db->query($sql); -if ($resql) -{ +if ($resql) { $num = $db->num_rows($resql); $arrayofselected = is_array($toselect) ? $toselect : array(); @@ -327,29 +391,71 @@ if ($resql) $expedition = new Expedition($db); $param = ''; - if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage); - if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit); - if ($sall) $param .= "&sall=".urlencode($sall); - if ($search_ref_exp) $param .= "&search_ref_exp=".urlencode($search_ref_exp); - if ($search_ref_liv) $param .= "&search_ref_liv=".urlencode($search_ref_liv); - if ($search_ref_customer) $param .= "&search_ref_customer=".urlencode($search_ref_customer); - if ($search_user > 0) $param .= '&search_user='.urlencode($search_user); - if ($search_sale > 0) $param .= '&search_sale='.urlencode($search_sale); - if ($search_company) $param .= "&search_company=".urlencode($search_company); - if ($search_tracking) $param .= "&search_tracking=".urlencode($search_tracking); - if ($search_town) $param .= '&search_town='.urlencode($search_town); - if ($search_zip) $param .= '&search_zip='.urlencode($search_zip); - if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { + $param .= '&contextpage='.urlencode($contextpage); + } + if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); + } + if ($sall) { + $param .= "&sall=".urlencode($sall); + } + if ($search_ref_exp) { + $param .= "&search_ref_exp=".urlencode($search_ref_exp); + } + if ($search_ref_liv) { + $param .= "&search_ref_liv=".urlencode($search_ref_liv); + } + if ($search_ref_customer) { + $param .= "&search_ref_customer=".urlencode($search_ref_customer); + } + if ($search_user > 0) { + $param .= '&search_user='.urlencode($search_user); + } + if ($search_sale > 0) { + $param .= '&search_sale='.urlencode($search_sale); + } + if ($search_company) { + $param .= "&search_company=".urlencode($search_company); + } + if ($search_tracking) { + $param .= "&search_tracking=".urlencode($search_tracking); + } + if ($search_town) { + $param .= '&search_town='.urlencode($search_town); + } + if ($search_zip) { + $param .= '&search_zip='.urlencode($search_zip); + } + if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) { + $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty); + } - if ($search_datedelivery_start) $param .= '&search_datedelivery_start='.urlencode($search_datedelivery_start); - if ($search_datedelivery_end) $param .= '&search_datedelivery_end='.urlencode($search_datedelivery_end); - if ($search_datereceipt_start) $param .= '&search_datereceipt_start='.urlencode($search_datereceipt_start); - if ($search_datereceipt_end) $param .= '&search_datereceipt_end='.urlencode($search_datereceipt_end); + if ($search_datedelivery_start) { + $param .= '&search_datedelivery_start='.urlencode($search_datedelivery_start); + } + if ($search_datedelivery_end) { + $param .= '&search_datedelivery_end='.urlencode($search_datedelivery_end); + } + if ($search_datereceipt_start) { + $param .= '&search_datereceipt_start='.urlencode($search_datereceipt_start); + } + if ($search_datereceipt_end) { + $param .= '&search_datereceipt_end='.urlencode($search_datereceipt_end); + } - if ($search_product_category != '') $param .= '&search_product_category='.urlencode($search_product_category); - if ($search_categ_cus > 0) $param .= '&search_categ_cus='.urlencode($search_categ_cus); - if ($search_status != '') $param .= '&search_status='.urlencode($search_status); - if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss); + if ($search_product_category != '') { + $param .= '&search_product_category='.urlencode($search_product_category); + } + if ($search_categ_cus > 0) { + $param .= '&search_categ_cus='.urlencode($search_categ_cus); + } + if ($search_status != '') { + $param .= '&search_status='.urlencode($search_status); + } + if ($optioncss != '') { + $param .= '&optioncss='.urlencode($optioncss); + } // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; @@ -358,7 +464,9 @@ if ($resql) //'classifyclose'=>$langs->trans("Close"), TODO massive close shipment ie: when truck is charged 'presend' => $langs->trans("SendByMail"), ); - if (in_array($massaction, array('presend'))) $arrayofmassactions = array(); + if (in_array($massaction, array('presend'))) { + $arrayofmassactions = array(); + } $massactionbutton = $form->selectMassAction('', $arrayofmassactions); // Currently: a sending can't create from sending list @@ -369,7 +477,9 @@ if ($resql) $i = 0; print ''."\n"; - if ($optioncss != '') print ''; + if ($optioncss != '') { + print ''; + } print ''; print ''; print ''; @@ -384,34 +494,32 @@ if ($resql) $trackid = 'shi'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - if ($sall) - { - foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val); + if ($sall) { + foreach ($fieldstosearchall as $key => $val) { + $fieldstosearchall[$key] = $langs->trans($val); + } print '
'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'
'; } $moreforfilter = ''; - // If the user can view prospects other than his' - if ($user->rights->societe->client->voir || $socid) - { - $langs->load("commercial"); + // If the user can view prospects other than his' + if ($user->rights->societe->client->voir || $socid) { + $langs->load("commercial"); $moreforfilter .= '
'; - $moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': '; + $moreforfilter .= $langs->trans('ThirdPartiesOfSaleRepresentative').': '; $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200'); - $moreforfilter .= '
'; - } + $moreforfilter .= ''; + } // If the user can view other users - if ($user->rights->user->user->lire) - { + if ($user->rights->user->user->lire) { $moreforfilter .= '
'; $moreforfilter .= $langs->trans('LinkedToSpecificUsers').': '; $moreforfilter .= $form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); - $moreforfilter .= '
'; + $moreforfilter .= ''; } // If the user can view prospects other than his' - if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) - { + if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) { include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '
'; $moreforfilter .= $langs->trans('IncludingProductWithTag').': '; @@ -419,21 +527,22 @@ if ($resql) $moreforfilter .= $form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1); $moreforfilter .= '
'; } - if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) - { + if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '
'; - $moreforfilter .= $langs->trans('CustomersProspectsCategoriesShort').': '; + $moreforfilter .= $langs->trans('CustomersProspectsCategoriesShort').': '; $moreforfilter .= $formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1); - $moreforfilter .= '
'; + $moreforfilter .= ''; } $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; - else $moreforfilter = $hookmanager->resPrint; + if (empty($reshook)) { + $moreforfilter .= $hookmanager->resPrint; + } else { + $moreforfilter = $hookmanager->resPrint; + } - if (!empty($moreforfilter)) - { + if (!empty($moreforfilter)) { print '
'; print $moreforfilter; print '
'; @@ -441,7 +550,9 @@ if ($resql) $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); - if ($massactionbutton) $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields + if ($massactionbutton) { + $selectedfields .= $form->showCheckAddButtons('checkforselect', 1); // This also change content of $arrayfields + } print '
'; print ''."\n"; @@ -449,61 +560,57 @@ if ($resql) // Fields title search print ''; // Ref - if (!empty($arrayfields['e.ref']['checked'])) - { + if (!empty($arrayfields['e.ref']['checked'])) { print ''; } // Ref customer - if (!empty($arrayfields['e.ref_customer']['checked'])) - { + if (!empty($arrayfields['e.ref_customer']['checked'])) { print ''; } // Thirdparty - if (!empty($arrayfields['s.nom']['checked'])) - { + if (!empty($arrayfields['s.nom']['checked'])) { print ''; } // Town - if (!empty($arrayfields['s.town']['checked'])) print ''; + if (!empty($arrayfields['s.town']['checked'])) { + print ''; + } // Zip - if (!empty($arrayfields['s.zip']['checked'])) print ''; + if (!empty($arrayfields['s.zip']['checked'])) { + print ''; + } // State - if (!empty($arrayfields['state.nom']['checked'])) - { + if (!empty($arrayfields['state.nom']['checked'])) { print ''; } // Country - if (!empty($arrayfields['country.code_iso']['checked'])) - { + if (!empty($arrayfields['country.code_iso']['checked'])) { print ''; } // Company type - if (!empty($arrayfields['typent.code']['checked'])) - { + if (!empty($arrayfields['typent.code']['checked'])) { print ''; } // Weight - if (!empty($arrayfields['e.weight']['checked'])) - { + if (!empty($arrayfields['e.weight']['checked'])) { print ''; } // Date delivery planned - if (!empty($arrayfields['e.date_delivery']['checked'])) - { + if (!empty($arrayfields['e.date_delivery']['checked'])) { print ''; } // Tracking number - if (!empty($arrayfields['e.tracking_number']['checked'])) - { + if (!empty($arrayfields['e.tracking_number']['checked'])) { print ''; } - if (!empty($arrayfields['l.ref']['checked'])) - { + if (!empty($arrayfields['l.ref']['checked'])) { // Delivery ref print ''; } // Date modification - if (!empty($arrayfields['e.tms']['checked'])) - { + if (!empty($arrayfields['e.tms']['checked'])) { print ''; } // Status - if (!empty($arrayfields['e.fk_statut']['checked'])) - { + if (!empty($arrayfields['e.fk_statut']['checked'])) { print ''; } // Status billed - if (!empty($arrayfields['e.billed']['checked'])) - { + if (!empty($arrayfields['e.billed']['checked'])) { print ''; @@ -584,37 +684,70 @@ if ($resql) print "\n"; print ''; - if (!empty($arrayfields['e.ref']['checked'])) print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['e.ref_customer']['checked'])) print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left '); - if (!empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['e.weight']['checked'])) print_liste_field_titre($arrayfields['e.weight']['label'], $_SERVER["PHP_SELF"], "e.weight", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['e.date_delivery']['checked'])) print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['e.tracking_number']['checked'])) print_liste_field_titre($arrayfields['e.tracking_number']['label'], $_SERVER["PHP_SELF"], "e.tracking_number", "", $param, '', $sortfield, $sortorder, 'center '); - if (!empty($arrayfields['l.ref']['checked'])) print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder); - if (!empty($arrayfields['l.date_delivery']['checked'])) print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['e.ref']['checked'])) { + print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['e.ref_customer']['checked'])) { + print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['s.nom']['checked'])) { + print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder, 'left '); + } + if (!empty($arrayfields['s.town']['checked'])) { + print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['s.zip']['checked'])) { + print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['state.nom']['checked'])) { + print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['country.code_iso']['checked'])) { + print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['typent.code']['checked'])) { + print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['e.weight']['checked'])) { + print_liste_field_titre($arrayfields['e.weight']['label'], $_SERVER["PHP_SELF"], "e.weight", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['e.date_delivery']['checked'])) { + print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['e.tracking_number']['checked'])) { + print_liste_field_titre($arrayfields['e.tracking_number']['label'], $_SERVER["PHP_SELF"], "e.tracking_number", "", $param, '', $sortfield, $sortorder, 'center '); + } + if (!empty($arrayfields['l.ref']['checked'])) { + print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder); + } + if (!empty($arrayfields['l.date_delivery']['checked'])) { + print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, '', $sortfield, $sortorder, 'center '); + } // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php'; // Hook fields $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder); $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - if (!empty($arrayfields['e.datec']['checked'])) print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - if (!empty($arrayfields['e.tms']['checked'])) print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); - if (!empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right '); - if (!empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center '); + if (!empty($arrayfields['e.datec']['checked'])) { + print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + } + if (!empty($arrayfields['e.tms']['checked'])) { + print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap '); + } + if (!empty($arrayfields['e.fk_statut']['checked'])) { + print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, '', $sortfield, $sortorder, 'right '); + } + if (!empty($arrayfields['e.billed']['checked'])) { + print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, '', $sortfield, $sortorder, 'center '); + } print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print "\n"; $typenArray = $formcompany->typent_array(1); $i = 0; $totalarray = array(); - while ($i < min($num, $limit)) - { + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); $shipment->id = $obj->rowid; @@ -630,76 +763,84 @@ if ($resql) print ''; // Ref - if (!empty($arrayfields['e.ref']['checked'])) - { + if (!empty($arrayfields['e.ref']['checked'])) { print "\n"; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Ref customer - if (!empty($arrayfields['e.ref_customer']['checked'])) - { + if (!empty($arrayfields['e.ref_customer']['checked'])) { print "\n"; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Third party - if (!empty($arrayfields['s.nom']['checked'])) - { + if (!empty($arrayfields['s.nom']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Town - if (!empty($arrayfields['s.town']['checked'])) - { + if (!empty($arrayfields['s.town']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Zip - if (!empty($arrayfields['s.zip']['checked'])) - { + if (!empty($arrayfields['s.zip']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // State - if (!empty($arrayfields['state.nom']['checked'])) - { + if (!empty($arrayfields['state.nom']['checked'])) { print "\n"; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Country - if (!empty($arrayfields['country.code_iso']['checked'])) - { + if (!empty($arrayfields['country.code_iso']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Type ent - if (!empty($arrayfields['typent.code']['checked'])) - { + if (!empty($arrayfields['typent.code']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Weight - if (!empty($arrayfields['e.weight']['checked'])) - { + if (!empty($arrayfields['e.weight']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date delivery planed - if (!empty($arrayfields['e.date_delivery']['checked'])) - { + if (!empty($arrayfields['e.date_delivery']['checked'])) { print '\n"; } // Tracking number - if (!empty($arrayfields['e.tracking_number']['checked'])) - { + if (!empty($arrayfields['e.tracking_number']['checked'])) { print '\n"; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } - if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) - { + if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked'])) { $shipment->fetchObjectLinked($shipment->id, $shipment->element); $receiving = ''; - if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving = reset($shipment->linkedObjects['delivery']); + if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) { + $receiving = reset($shipment->linkedObjects['delivery']); + } - if (!empty($arrayfields['l.ref']['checked'])) - { + if (!empty($arrayfields['l.ref']['checked'])) { // Ref print ''; } - if (!empty($arrayfields['l.date_delivery']['checked'])) - { + if (!empty($arrayfields['l.date_delivery']['checked'])) { // Date received print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Date modification - if (!empty($arrayfields['e.tms']['checked'])) - { + if (!empty($arrayfields['e.tms']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Status - if (!empty($arrayfields['e.fk_statut']['checked'])) - { + if (!empty($arrayfields['e.fk_statut']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Billed - if (!empty($arrayfields['e.billed']['checked'])) - { + if (!empty($arrayfields['e.billed']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Action column print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } print "\n"; @@ -812,7 +961,9 @@ if ($resql) print ''; $hidegeneratedfilelistifempty = 1; - if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) $hidegeneratedfilelistifempty = 0; + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { + $hidegeneratedfilelistifempty = 0; + } // Show list of available documents $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; diff --git a/htdocs/expedition/note.php b/htdocs/expedition/note.php index 6397a301e59..c8209910b48 100644 --- a/htdocs/expedition/note.php +++ b/htdocs/expedition/note.php @@ -41,30 +41,28 @@ $action = GETPOST('action', 'aZ09'); // Security check $socid = ''; -if ($user->socid) $socid = $user->socid; +if ($user->socid) { + $socid = $user->socid; +} $result = restrictedArea($user, $origin, $origin_id); $object = new Expedition($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $object->fetch($id, $ref); $object->fetch_thirdparty(); - if (!empty($object->origin)) - { + if (!empty($object->origin)) { $typeobject = $object->origin; $origin = $object->origin; $object->fetch_origin(); } // Linked documents - if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) - { + if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled)) { $objectsrc = new Commande($db); $objectsrc->fetch($object->$typeobject->id); } - if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) - { + if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled)) { $objectsrc = new Propal($db); $objectsrc->fetch($object->$typeobject->id); } @@ -88,8 +86,7 @@ llxHeader(); $form = new Form($db); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $head = shipping_prepare_head($object); print dol_get_fiche_head($head, 'note', $langs->trans("Shipment"), -1, 'sending'); diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 1c4e5bf5c25..66efd5c4ca7 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -37,9 +37,15 @@ 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'; } -if (!empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; -if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; -if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +if (!empty($conf->stock->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; +} +if (!empty($conf->propal->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; +} +if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +} // Load translation files required by the page $langs->loadLangs(array('orders', "companies", "bills", 'propal', 'deliveries', 'stocks', "productbatch", 'incoterm', 'other')); @@ -53,7 +59,9 @@ $hookmanager->initHooks(array('ordershipmentcard')); // Security check $socid = 0; -if (!empty($user->socid)) $socid = $user->socid; +if (!empty($user->socid)) { + $socid = $user->socid; +} $result = restrictedArea($user, 'commande', $id); $object = new Commande($db); @@ -74,93 +82,86 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be includ $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 (empty($reshook)) { // Categorisation dans projet - if ($action == 'classin') - { + if ($action == 'classin') { $object = new Commande($db); $object->fetch($id); $object->setProject(GETPOST('projectid', 'int')); } - if ($action == 'confirm_cloture' && GETPOST('confirm', 'alpha') == 'yes') - { + if ($action == 'confirm_cloture' && GETPOST('confirm', 'alpha') == 'yes') { $object = new Commande($db); $object->fetch($id); $result = $object->cloture($user); - } - - // Positionne ref commande client - elseif ($action == 'setref_client' && $user->rights->commande->creer) { + } elseif ($action == 'setref_client' && $user->rights->commande->creer) { + // Positionne ref commande client $result = $object->set_ref_client($user, GETPOST('ref_client')); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } - if ($action == 'setdatedelivery' && $user->rights->commande->creer) - { + if ($action == 'setdatedelivery' && $user->rights->commande->creer) { //print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; $datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int')); $object->fetch($id); $result = $object->setDeliveryDate($user, $datedelivery); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } /* - if ($action == 'setdeliveryaddress' && $user->rights->commande->creer) - { - $object = new Commande($db); - $object->fetch($id); - $object->setDeliveryAddress(GETPOST('delivery_address_id','int')); - if ($result < 0) - setEventMessages($object->error, $object->errors, 'errors'); - } - */ - if ($action == 'setmode' && $user->rights->commande->creer) + if ($action == 'setdeliveryaddress' && $user->rights->commande->creer) { $object = new Commande($db); $object->fetch($id); - $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + $object->setDeliveryAddress(GETPOST('delivery_address_id','int')); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } + */ + if ($action == 'setmode' && $user->rights->commande->creer) { + $object = new Commande($db); + $object->fetch($id); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } if ($action == 'setavailability' && $user->rights->commande->creer) { $object = new Commande($db); $object->fetch($id); $result = $object->availability(GETPOST('availability_id')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } } if ($action == 'setdemandreason' && $user->rights->commande->creer) { $object = new Commande($db); $object->fetch($id); $result = $object->demand_reason(GETPOST('demand_reason_id')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } } - if ($action == 'setconditions' && $user->rights->commande->creer) - { + if ($action == 'setconditions' && $user->rights->commande->creer) { $object = new Commande($db); $object->fetch($id); $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); - } - - // Set incoterm - elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) - { + } + } elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) { + // Set incoterm $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -172,8 +173,9 @@ if (empty($reshook)) $object = new Commande($db); $object->fetch($id); $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } } // warehouse @@ -181,35 +183,35 @@ if (empty($reshook)) $object = new Commande($db); $object->fetch($id); $result = $object->setWarehouse(GETPOST('warehouse_id', 'int')); - if ($result < 0) + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); + } } - if ($action == 'update_extras') - { + if ($action == 'update_extras') { $object->oldcopy = dol_clone($object); // Fill array 'array_options' with data from update 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 $result = $object->insertExtraFields('SHIPMENT_MODIFY'); - if ($result < 0) - { + if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); $error++; } } - if ($error) + if ($error) { $action = 'edit_extras'; + } } - if ($action == 'set_thirdparty' && $user->rights->commande->creer) - { + if ($action == 'set_thirdparty' && $user->rights->commande->creer) { $object->fetch($id); $object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY'); @@ -227,16 +229,16 @@ if (empty($reshook)) $form = new Form($db); $formfile = new FormFile($db); $formproduct = new FormProduct($db); -if (!empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } +if (!empty($conf->projet->enabled)) { + $formproject = new FormProjets($db); +} llxHeader('', $langs->trans('OrderCard'), ''); -if ($id > 0 || !empty($ref)) -{ +if ($id > 0 || !empty($ref)) { $object = new Commande($db); - if ($object->fetch($id, $ref) > 0) - { + if ($object->fetch($id, $ref) > 0) { $object->loadExpeditions(1); $product_static = new Product($db); @@ -256,16 +258,18 @@ if ($id > 0 || !empty($ref)) $formconfirm = ''; // Confirm validation - if ($action == 'cloture') - { + if ($action == 'cloture') { $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$id, $langs->trans("CloseShipment"), $langs->trans("ConfirmCloseShipment"), "confirm_cloture"); } // Call Hook formConfirm $parameters = array('formConfirm' => $formconfirm); $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) $formconfirm .= $hookmanager->resPrint; - elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint; + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } // Print form confirm print $formconfirm; @@ -283,12 +287,10 @@ if ($id > 0 || !empty($ref)) // Thirdparty $morehtmlref .= '
'.$langs->trans('ThirdParty').' : '.$soc->getNomUrl(1); // Project - if (!empty($conf->projet->enabled)) - { + if (!empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref .= '
'.$langs->trans('Project').' '; - if ($user->rights->commande->creer) - { + if ($user->rights->commande->creer) { if ($action != 'classify') { $morehtmlref .= ''.img_edit($langs->transnoentitiesnoconv('SetProject')).' : '; } @@ -366,11 +368,12 @@ if ($id > 0 || !empty($ref)) print $langs->trans('DateDeliveryPlanned'); print ''; - if ($action != 'editdate_livraison') print ''; + if ($action != 'editdate_livraison') { + print ''; + } print '
'; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100'); print ''; print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1); print ''; print ''; print '
'; print $langs->trans('From').' '; @@ -516,21 +623,18 @@ if ($resql) print '
'; print ''; print ''; print ''; } - if (!empty($arrayfields['l.date_delivery']['checked'])) - { + if (!empty($arrayfields['l.date_delivery']['checked'])) { // Date received print ''; print '
'; @@ -551,27 +655,23 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['e.datec']['checked'])) - { + if (!empty($arrayfields['e.datec']['checked'])) { print '
'; print ''; print ''; print $form->selectarray('search_status', array('0'=>$langs->trans('StatusSendingDraftShort'), '1'=>$langs->trans('StatusSendingValidatedShort'), '2'=>$langs->trans('StatusSendingProcessedShort')), $search_status, 1); print ''; print $form->selectyesno('search_billed', $search_billed, 1, 0, 1); print '
"; print $shipment->getNomUrl(1); print ""; print $obj->ref_customer; print "'; print $companystatic->getNomUrl(1); print ''; print $obj->town; print ''; print $obj->zip; print '".$obj->state_name."'; $tmparray = getCountry($obj->fk_pays, 'all'); print $tmparray['label']; print ''; - if (isset($typenArray[$obj->typent_code])) print $typenArray[$obj->typent_code]; + if (isset($typenArray[$obj->typent_code])) { + print $typenArray[$obj->typent_code]; + } print ''; - if (empty($object->trueWeight)) - { + if (empty($object->trueWeight)) { $tmparray = $object->getTotalWeightVolume(); print showDimensionInBestUnit($tmparray['weight'], 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no'); print $form->textwithpicto('', $langs->trans('EstimatedWeight'), 1); @@ -708,42 +849,43 @@ if ($resql) print ($object->trueWeight && $object->weight_units != '') ? ' '.measuringUnitString(0, "weight", $object->weight_units) : ''; } print ''; print dol_print_date($db->jdate($obj->delivery_date), "dayhour"); /*$now = time(); - if ( ($now - $db->jdate($obj->date_expedition)) > $conf->warnings->lim && $obj->statutid == 1 ) - { - }*/ + if ( ($now - $db->jdate($obj->date_expedition)) > $conf->warnings->lim && $obj->statutid == 1 ) + { + }*/ print "'.$obj->tracking_number."'; print !empty($receiving) ? $receiving->getNomUrl($db) : ''; print ''; print dol_print_date($db->jdate($obj->date_reception), "day"); @@ -758,44 +900,51 @@ if ($resql) $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation - if (!empty($arrayfields['e.datec']['checked'])) - { + if (!empty($arrayfields['e.datec']['checked'])) { print ''; print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); print ''; print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); print ''.$shipment->LibStatut($obj->fk_statut, 5).''.yn($obj->billed).''; - if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined - { + if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; - if (in_array($obj->rowid, $arrayofselected)) $selected = 1; + if (in_array($obj->rowid, $arrayofselected)) { + $selected = 1; + } print ''; } print '
id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'
'; print ''; - if ($action == 'editdate_livraison') - { + if ($action == 'editdate_livraison') { print '
'; print ''; print ''; @@ -395,8 +398,9 @@ if ($id > 0 || !empty($ref)) print ''; - if ($action != 'editshippingmethod' && $user->rights->expedition->creer) + if ($action != 'editshippingmethod' && $user->rights->expedition->creer) { print ''; + } print '
'; print $langs->trans('SendingMethod'); print 'id.'">'.img_edit($langs->trans('SetShippingMode'), 1).'
'; print ''; if ($action == 'editshippingmethod') { @@ -415,8 +419,9 @@ if ($id > 0 || !empty($ref)) print ''; - if ($action != 'editwarehouse' && $user->rights->commande->creer) + if ($action != 'editwarehouse' && $user->rights->commande->creer) { print ''; + } print '
'; print $langs->trans('Warehouse'); print 'id.'">'.img_edit($langs->trans('SetWarehouse'), 1).'
'; print ''; if ($action == 'editwarehouse') { @@ -471,8 +476,9 @@ if ($id > 0 || !empty($ref)) print ''; - if ($action != 'editavailability') + if ($action != 'editavailability') { print ''; + } print '
'; print $langs->trans('AvailabilityPeriod'); print 'id.'">'.img_edit($langs->trans('SetAvailability'), 1).'
'; print ''; if ($action == 'editavailability') { @@ -487,8 +493,9 @@ if ($id > 0 || !empty($ref)) print ''; - if ($action != 'editdemandreason') + if ($action != 'editdemandreason') { print ''; + } print '
'; print $langs->trans('Source'); print 'id.'">'.img_edit($langs->trans('SetDemandReason'), 1).'
'; print ''; if ($action == 'editdemandreason') { @@ -500,8 +507,7 @@ if ($id > 0 || !empty($ref)) $tmparray = $object->getTotalWeightVolume(); $totalWeight = $tmparray['weight']; $totalVolume = $tmparray['volume']; - if ($totalWeight || $totalVolume) - { + if ($totalWeight || $totalVolume) { print ''.$langs->trans("CalculatedWeight").''; print ''; print showDimensionInBestUnit($totalWeight, 0, "weight", $langs, isset($conf->global->MAIN_WEIGHT_DEFAULT_ROUND) ? $conf->global->MAIN_WEIGHT_DEFAULT_ROUND : -1, isset($conf->global->MAIN_WEIGHT_DEFAULT_UNIT) ? $conf->global->MAIN_WEIGHT_DEFAULT_UNIT : 'no'); @@ -515,19 +521,20 @@ if ($id > 0 || !empty($ref)) // TODO How record was recorded OrderMode (llx_c_input_method) // Incoterms - if (!empty($conf->incoterm->enabled)) - { + if (!empty($conf->incoterm->enabled)) { print ''; print '
'; print $langs->trans('IncotermLabel'); print ''; - if ($user->rights->commande->creer) print ''.img_edit().''; - else print ' '; + if ($user->rights->commande->creer) { + print ''.img_edit().''; + } else { + print ' '; + } print '
'; print ''; print ''; - if ($action != 'editincoterm') - { + if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1); } else { print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id); @@ -551,8 +558,7 @@ if ($id > 0 || !empty($ref)) print ''; - if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) - { + if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { // Multicurrency Amount HT print ''; print ''; @@ -579,13 +585,11 @@ if ($id > 0 || !empty($ref)) print ''; // Amount Local Taxes - if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) // Localtax1 - { + if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1 print ''; print ''; } - if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) // Localtax2 IRPF - { + if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2 IRPF print ''; print ''; } @@ -627,8 +631,7 @@ if ($id > 0 || !empty($ref)) //print $sql; dol_syslog("shipment.php", LOG_DEBUG); $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; @@ -637,8 +640,7 @@ if ($id > 0 || !empty($ref)) print ''; print ''; print ''; - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { print ''; } else { print ''; @@ -647,32 +649,34 @@ if ($id > 0 || !empty($ref)) $toBeShipped = array(); $toBeShippedTotal = 0; - while ($i < $num) - { + while ($i < $num) { $objp = $db->fetch_object($resql); $parameters = array('i' => $i, 'line' => $objp, 'num' => $num); $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $object, $action); - if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } - if (empty($reshook)) - { + if (empty($reshook)) { // Show product and description $type = isset($objp->type) ? $objp->type : $objp->product_type; // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. - if (!empty($objp->date_start)) $type = 1; - if (!empty($objp->date_end)) $type = 1; + if (!empty($objp->date_start)) { + $type = 1; + } + if (!empty($objp->date_end)) { + $type = 1; + } print ''; // Product label - if ($objp->fk_product > 0) - { + if ($objp->fk_product > 0) { // Define output language - if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) - { + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $object->fetch_thirdparty(); $prod = new Product($db); @@ -682,16 +686,21 @@ if ($id > 0 || !empty($ref)) $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && !empty($_REQUEST['lang_id'])) $newlang = $_REQUEST['lang_id']; - if (empty($newlang)) $newlang = $object->thirdparty->default_lang; - if (!empty($newlang)) - { + if (empty($newlang) && !empty($_REQUEST['lang_id'])) { + $newlang = $_REQUEST['lang_id']; + } + if (empty($newlang)) { + $newlang = $object->thirdparty->default_lang; + } + if (!empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label; - } else $label = (!empty($objp->label) ? $objp->label : $objp->product_label); + } else { + $label = (!empty($objp->label) ? $objp->label : $objp->product_label); + } print ''; } else { print "'; - if ($objp->fk_product > 0) - { + if ($objp->fk_product > 0) { $product = new Product($db); $product->fetch($objp->fk_product); $product->load_stock('warehouseopen'); } - if ($objp->fk_product > 0 && ($type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && !empty($conf->stock->enabled)) - { + if ($objp->fk_product > 0 && ($type == Product::TYPE_PRODUCT || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) && !empty($conf->stock->enabled)) { print ''; @@ -793,8 +800,7 @@ if ($id > 0 || !empty($ref)) print "\n"; // Show subproducts lines - if ($objp->fk_product > 0 && !empty($conf->global->PRODUIT_SOUSPRODUITS)) - { + if ($objp->fk_product > 0 && !empty($conf->global->PRODUIT_SOUSPRODUITS)) { // Set tree of subproducts in product->sousprods $product->get_sousproduits_arbo(); //var_dump($product->sousprods);exit; @@ -802,13 +808,10 @@ if ($id > 0 || !empty($ref)) // Define a new tree with quantiies recalculated $prods_arbo = $product->get_arbo_each_prod($qtyProdCom); //var_dump($prods_arbo); - if (count($prods_arbo) > 0) - { - foreach ($prods_arbo as $key => $value) - { + if (count($prods_arbo) > 0) { + foreach ($prods_arbo as $key => $value) { $img = ''; - if ($value['stock'] < $value['stock_alert']) - { + if ($value['stock'] < $value['stock_alert']) { $img = img_warning($langs->trans("StockTooLow")); } print ''; @@ -824,8 +827,7 @@ if ($id > 0 || !empty($ref)) } $db->free($resql); - if (!$num) - { + if (!$num) { print ''; - if (!empty($conf->stock->enabled)) - { + if (!empty($conf->stock->enabled)) { //print ''; //print ''; } //print ''; diff --git a/htdocs/expedition/stats/index.php b/htdocs/expedition/stats/index.php index fcc0d26f81c..151edbdba2b 100644 --- a/htdocs/expedition/stats/index.php +++ b/htdocs/expedition/stats/index.php @@ -34,8 +34,7 @@ $HEIGHT = DolGraph::getDefaultGraphSizeForStats('height'); $userid = GETPOST('userid', 'int'); $socid = GETPOST('socid', 'int'); // Security check -if ($user->socid > 0) -{ +if ($user->socid > 0) { $action = ''; $socid = $user->socid; } @@ -71,8 +70,7 @@ $data = $stats->getNbByMonthWithPrevYear($endyear, $startyear); // $data = array(array('Lib',val1,val2,val3),...) -if (!$user->rights->societe->client->voir || $user->socid) -{ +if (!$user->rights->societe->client->voir || $user->socid) { $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; } else { $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png'; @@ -80,12 +78,10 @@ if (!$user->rights->societe->client->voir || $user->socid) $px1 = new DolGraph(); $mesg = $px1->isGraphKo(); -if (!$mesg) -{ +if (!$mesg) { $px1->SetData($data); $i = $startyear; $legend = array(); - while ($i <= $endyear) - { + while ($i <= $endyear) { $legend[] = $i; $i++; } @@ -111,36 +107,36 @@ $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear); if (!$user->rights->societe->client->voir || $user->socid) { - $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; + $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; } else { - $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png'; + $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png'; } $px2 = new DolGraph(); $mesg = $px2->isGraphKo(); if (! $mesg) { - $px2->SetData($data); - $i=$startyear;$legend=array(); - while ($i <= $endyear) - { - $legend[]=$i; - $i++; - } - $px2->SetLegend($legend); - $px2->SetMaxValue($px2->GetCeilMaxValue()); - $px2->SetMinValue(min(0,$px2->GetFloorMinValue())); - $px2->SetWidth($WIDTH); - $px2->SetHeight($HEIGHT); - $px2->SetYLabel($langs->trans("AmountOfShipments")); - $px2->SetShading(3); - $px2->SetHorizTickIncrement(1); - $px2->mode='depth'; - $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT")); + $px2->SetData($data); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px2->SetLegend($legend); + $px2->SetMaxValue($px2->GetCeilMaxValue()); + $px2->SetMinValue(min(0,$px2->GetFloorMinValue())); + $px2->SetWidth($WIDTH); + $px2->SetHeight($HEIGHT); + $px2->SetYLabel($langs->trans("AmountOfShipments")); + $px2->SetShading(3); + $px2->SetHorizTickIncrement(1); + $px2->mode='depth'; + $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT")); - $px2->draw($filenameamount,$fileurlamount); + $px2->draw($filenameamount,$fileurlamount); } */ @@ -149,36 +145,36 @@ $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear); if (!$user->rights->societe->client->voir || $user->socid) { - $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png'; + $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png'; } else { - $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png'; + $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png'; } $px3 = new DolGraph(); $mesg = $px3->isGraphKo(); if (! $mesg) { - $px3->SetData($data); - $i=$startyear;$legend=array(); - while ($i <= $endyear) - { - $legend[]=$i; - $i++; - } - $px3->SetLegend($legend); - $px3->SetYLabel($langs->trans("AmountAverage")); - $px3->SetMaxValue($px3->GetCeilMaxValue()); - $px3->SetMinValue($px3->GetFloorMinValue()); - $px3->SetWidth($WIDTH); - $px3->SetHeight($HEIGHT); - $px3->SetShading(3); - $px3->SetHorizTickIncrement(1); - $px3->mode='depth'; - $px3->SetTitle($langs->trans("AmountAverage")); + $px3->SetData($data); + $i=$startyear;$legend=array(); + while ($i <= $endyear) + { + $legend[]=$i; + $i++; + } + $px3->SetLegend($legend); + $px3->SetYLabel($langs->trans("AmountAverage")); + $px3->SetMaxValue($px3->GetCeilMaxValue()); + $px3->SetMinValue($px3->GetFloorMinValue()); + $px3->SetWidth($WIDTH); + $px3->SetHeight($HEIGHT); + $px3->SetShading(3); + $px3->SetHorizTickIncrement(1); + $px3->mode='depth'; + $px3->SetTitle($langs->trans("AmountAverage")); - $px3->draw($filename_avg,$fileurl_avg); + $px3->draw($filename_avg,$fileurl_avg); } */ @@ -191,7 +187,9 @@ foreach ($data as $val) { $arrayyears[$val['year']] = $val['year']; } } -if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear; +if (!count($arrayyears)) { + $arrayyears[$nowyear] = $nowyear; +} $h = 0; $head = array(); @@ -228,8 +226,12 @@ print '
'; print ''; // Year print '
'; @@ -250,11 +252,9 @@ print '';*/ print ''; $oldyear = 0; -foreach ($data as $val) -{ +foreach ($data as $val) { $year = $val['year']; - while (!empty($year) && $oldyear > $year + 1) - { // If we have empty year + while (!empty($year) && $oldyear > $year + 1) { // If we have empty year $oldyear--; @@ -292,12 +292,14 @@ print '
'; // Show graphs print '
'.$form->editfieldkey('MulticurrencyAmountHT', 'multicurrency_total_ht', '', $object, 0).''.price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).'
'.$langs->transcountry("AmountLT1", $mysoc->country_code).''.price($object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->transcountry("AmountLT2", $mysoc->country_code).''.price($object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'
'.$langs->trans("QtyOrdered").''.$langs->trans("QtyShipped").''.$langs->trans("KeepToShip").''.$langs->trans("RealStock").' 
'; print ''; // ancre pour retourner sur la ligne @@ -725,16 +734,18 @@ if ($id > 0 || !empty($ref)) print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end)); // Add description in form - if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) - { + if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) { print ($objp->description && $objp->description != $objp->product_label) ? '
'.dol_htmlentitiesbr($objp->description) : ''; } print '
"; - if ($type == 1) $text = img_object($langs->trans('Service'), 'service'); - else $text = img_object($langs->trans('Product'), 'product'); + if ($type == 1) { + $text = img_object($langs->trans('Service'), 'service'); + } else { + $text = img_object($langs->trans('Product'), 'product'); + } if (!empty($objp->label)) { $text .= ' '.$objp->label.''; @@ -761,8 +772,7 @@ if ($id > 0 || !empty($ref)) // Qty remains to ship print ''; - if ($type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) - { + if ($type == 0 || !empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $toBeShipped[$objp->fk_product] = $objp->qty - $qtyAlreadyShipped; $toBeShippedTotal += $toBeShipped[$objp->fk_product]; print $toBeShipped[$objp->fk_product]; @@ -771,19 +781,16 @@ if ($id > 0 || !empty($ref)) } print ''; print $product->stock_reel; - if ($product->stock_reel < $toBeShipped[$objp->fk_product]) - { + if ($product->stock_reel < $toBeShipped[$objp->fk_product]) { print ' '.img_warning($langs->trans("StockTooLow")); } print '
      -> '.$value['fullpath'].' ('.$value['nb'].')
'.$langs->trans("NoArticleOfTypeProduct").'
'; } @@ -841,18 +843,14 @@ if ($id > 0 || !empty($ref)) * Boutons Actions */ - if (empty($user->socid)) - { + if (empty($user->socid)) { print '
'; // Bouton expedier sans gestion des stocks - if (empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) - { - if ($user->rights->expedition->creer) - { + if (empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) { + if ($user->rights->expedition->creer) { print ''.$langs->trans("CreateShipment").''; - if ($toBeShippedTotal <= 0) - { + if ($toBeShippedTotal <= 0) { print ' '.img_warning($langs->trans("WarningNoQtyLeftToSend")); } } else { @@ -865,15 +863,12 @@ if ($id > 0 || !empty($ref)) // Bouton expedier avec gestion des stocks - if (!empty($conf->stock->enabled) && $object->statut == Commande::STATUS_DRAFT) - { + if (!empty($conf->stock->enabled) && $object->statut == Commande::STATUS_DRAFT) { print $langs->trans("ValidateOrderFirstBeforeShipment"); } - if (!empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) - { - if ($user->rights->expedition->creer) - { + if (!empty($conf->stock->enabled) && ($object->statut > Commande::STATUS_DRAFT && $object->statut < Commande::STATUS_CLOSED)) { + if ($user->rights->expedition->creer) { //print load_fiche_titre($langs->trans("CreateShipment")); print '
'; @@ -890,23 +885,20 @@ if ($id > 0 || !empty($ref)) //print '
'; print $langs->trans("WarehouseSource"); //print ''; print $formproduct->selectWarehouses(!empty($object->warehouse_id) ? $object->warehouse_id : 'ifone', 'entrepot_id', '', 1, 0, 0, '', 0, 0, array(), 'minwidth200'); - if (count($formproduct->cache_warehouses) <= 0) - { + if (count($formproduct->cache_warehouses) <= 0) { print '   '.$langs->trans("WarehouseSourceNotDefined").' '.$langs->trans("AddOne").''; } //print ''; print ''; - if ($toBeShippedTotal <= 0) - { + if ($toBeShippedTotal <= 0) { print ' '.img_warning($langs->trans("WarningNoQtyLeftToSend")); } //print '
'.$langs->trans("Year").''; - if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year; - if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear; +if (!in_array($year, $arrayyears)) { + $arrayyears[$year] = $year; +} +if (!in_array($nowyear, $arrayyears)) { + $arrayyears[$nowyear] = $nowyear; +} arsort($arrayyears); print $form->selectarray('year', $arrayyears, $year, 0); print '
'.$langs->trans("AmountAverage").'
'; -if ($mesg) { print $mesg; } else { +if ($mesg) { + print $mesg; +} else { print $px1->show(); print "
\n"; /*print $px2->show(); - print "
\n"; - print $px3->show();*/ + print "
\n"; + print $px3->show();*/ } print '
'; @@ -324,17 +326,17 @@ $sql.= " GROUP BY dm DESC"; $resql=$db->query($sql); if ($resql) { - $num = $db->num_rows($resql); - $i = 0; - while ($i < $num) - { - $row = $db->fetch_row($resql); - $nbproduct = $row[0]; - $year = $row[1]; - print ""; - print ''.$year.''.$nbproduct.''; - $i++; - } + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $row = $db->fetch_row($resql); + $nbproduct = $row[0]; + $year = $row[1]; + print ""; + print ''.$year.''.$nbproduct.''; + $i++; + } } $db->free($resql); diff --git a/htdocs/expedition/tpl/linkedobjectblock.tpl.php b/htdocs/expedition/tpl/linkedobjectblock.tpl.php index 897e35b8813..b00d63eaba1 100644 --- a/htdocs/expedition/tpl/linkedobjectblock.tpl.php +++ b/htdocs/expedition/tpl/linkedobjectblock.tpl.php @@ -17,8 +17,7 @@ */ // Protection to avoid direct call of template -if (empty($conf) || !is_object($conf)) -{ +if (empty($conf) || !is_object($conf)) { print "Error, template page can't be called as URL"; exit; } @@ -37,48 +36,49 @@ $langs->load("sendings"); $total = 0; $ilink = 0; -foreach ($linkedObjectBlock as $key => $objectlink) -{ +foreach ($linkedObjectBlock as $key => $objectlink) { $ilink++; $trclass = 'oddeven'; - if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) $trclass .= ' liste_sub_total'; + if ($ilink == count($linkedObjectBlock) && empty($noMoreLinkedObjectBlockAfter) && count($linkedObjectBlock) <= 1) { + $trclass .= ' liste_sub_total'; + } ?> - - trans("Shipment"); ?> - getNomUrl(1); ?> - - date_delivery, 'day'); ?> - "> + trans("Shipment"); ?> + getNomUrl(1); ?> + + date_delivery, 'day'); ?> + rights->expedition->lire) { $total = $total + $objectlink->total_ht; echo price($objectlink->total_ht); } ?> - getLibStatut(3); ?> - - getLibStatut(3); ?> + + element != 'commande') { ?> - ">transnoentitiesnoconv("RemoveLink"), 'unlink'); ?> - id.'&action=dellink&dellinkid='.$key; ?>">transnoentitiesnoconv("RemoveLink"), 'unlink'); ?> + - - + 1) { ?> - - trans("Total"); ?> - - - - - - - - "> + trans("Total"); ?> + + + + + + + + \n";