code syntax delivery directory

This commit is contained in:
Frédéric FRANCE 2021-02-25 22:15:04 +01:00
parent f7c119e48c
commit d97af3f849
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1
2 changed files with 221 additions and 255 deletions

View File

@ -34,12 +34,15 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
if (!empty($conf->product->enabled) || !empty($conf->service->enabled))
if (!empty($conf->product->enabled) || !empty($conf->service->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
if (!empty($conf->expedition_bon->enabled))
}
if (!empty($conf->expedition_bon->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
if (!empty($conf->stock->enabled))
}
if (!empty($conf->stock->enabled)) {
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.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';
@ -48,7 +51,9 @@ if (!empty($conf->projet->enabled)) {
// Load translation files required by the page
$langs->loadLangs(array("sendings", "bills", 'deliveries', 'orders'));
if (!empty($conf->incoterm->enabled)) $langs->load('incoterm');
if (!empty($conf->incoterm->enabled)) {
$langs->load('incoterm');
}
$action = GETPOST('action', 'aZ09');
$confirm = GETPOST('confirm', 'alpha');
@ -56,7 +61,9 @@ $backtopage = GETPOST('backtopage', 'alpha');
// Security check
$id = GETPOST('id', 'int');
if ($user->socid) $socid = $user->socid;
if ($user->socid) {
$socid = $user->socid;
}
$result = restrictedArea($user, 'expedition', $id, 'delivery', 'delivery');
$object = new Delivery($db);
@ -84,8 +91,7 @@ $error = 0;
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
if ($action == 'add')
{
if ($action == 'add') {
$db->begin();
$object->date_delivery = dol_now();
@ -103,13 +109,11 @@ if ($action == 'add')
$commande->fetch($object->commande_id);
$commande->fetch_lines();
$num = count($commande->lines);
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
$qty = "qtyl".$i;
$idl = "idl".$i;
$qtytouse = price2num(GETPOST($qty));
if ($qtytouse > 0)
{
if ($qtytouse > 0) {
$object->addline(GETPOST($idl), price2num($qtytouse));
}
}
@ -128,17 +132,19 @@ if ($action == 'add')
} elseif ($action == 'confirm_valid' && $confirm == 'yes' &&
((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate)))
)
{
) {
$result = $object->valid($user);
// 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);
@ -147,74 +153,70 @@ if ($action == 'add')
$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);
}
}
}
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->delivery->supprimer)
{
if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->expedition->delivery->supprimer) {
$db->begin();
$result = $object->delete();
if ($result > 0)
{
if ($result > 0) {
$db->commit();
if (!empty($backtopage)) header("Location: ".$backtopage);
else header("Location: ".DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1');
if (!empty($backtopage)) {
header("Location: ".$backtopage);
} else {
header("Location: ".DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1');
}
exit;
} else {
$db->rollback();
}
}
if ($action == 'setdate_delivery' && $user->rights->expedition->delivery->creer)
{
if ($action == 'setdate_delivery' && $user->rights->expedition->delivery->creer) {
$datedelivery = dol_mktime(GETPOST('liv_hour', 'int'), GETPOST('liv_min', 'int'), 0, GETPOST('liv_month', 'int'), GETPOST('liv_day', 'int'), GETPOST('liv_year', 'int'));
$result = $object->setDeliveryDate($user, $datedelivery);
if ($result < 0)
{
if ($result < 0) {
$mesg = '<div class="error">'.$object->error.'</div>';
}
}
// Set incoterm
elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled))
{
} elseif ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) {
// Set incoterm
$result = $object->setIncoterms((int) GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
}
// Update extrafields
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('DELIVERY_MODIFY');
if ($result < 0)
{
if ($result < 0) {
setEventMessages($object->error, $object->errors, 'errors');
$error++;
}
}
if ($error)
if ($error) {
$action = 'edit_extras';
}
}
// Extrafields line
if ($action == 'update_extras_line')
{
if ($action == 'update_extras_line') {
$array_options = array();
$num = count($object->lines);
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
// Extrafields
$extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
$array_options[$i] = $extrafields->getOptionalsFromPost($extralabelsline, $i);
@ -227,8 +229,7 @@ if ($action == 'update_extras_line')
}
$ret = $object->update_line($object->lines[$i]->id, $array_options[$i]); // extrafields update
if ($ret < 0)
{
if ($ret < 0) {
$mesg = '<div class="error">'.$object->error.'</div>';
$error++;
}
@ -253,24 +254,20 @@ llxHeader('', $langs->trans('Delivery'), 'Livraison');
$form = new Form($db);
$formfile = new FormFile($db);
if ($action == 'create') // Create. Seems to no be used
{
if ($action == 'create') { // Create. Seems to no be used
} else // View
{
if ($object->id > 0)
{
if ($object->id > 0) {
// Origin of a 'livraison' (delivery receipt) is ALWAYS 'expedition' (shipment).
// However, origin of shipment in future may differs (commande, proposal, ...)
$expedition = new Expedition($db);
$result = $expedition->fetch($object->origin_id);
$typeobject = $expedition->origin; // example: commande
if ($object->origin_id > 0)
{
if ($object->origin_id > 0) {
$object->fetch_origin();
}
if ($object->id > 0)
{
if ($object->id > 0) {
$soc = new Societe($db);
$soc->fetch($object->socid);
@ -289,8 +286,7 @@ if ($action == 'create') // Create. Seems to no be used
* Confirmation de la suppression
*
*/
if ($action == 'delete')
{
if ($action == 'delete') {
$expedition_id = GETPOST("expid");
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id.'&expid='.$expedition_id.'&backtopage='.urlencode($backtopage), $langs->trans("DeleteDeliveryReceipt"), $langs->trans("DeleteDeliveryReceiptConfirm", $object->ref), 'confirm_delete', '', '', 1);
}
@ -298,8 +294,7 @@ if ($action == 'create') // Create. Seems to no be used
/*
* Confirmation de la validation
*/
if ($action == 'valid')
{
if ($action == 'valid') {
print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans("ValidateDeliveryReceipt"), $langs->trans("ValidateDeliveryReceiptConfirm", $object->ref), 'confirm_valid', '', '', 1);
}
@ -308,13 +303,11 @@ if ($action == 'create') // Create. Seems to no be used
* Delivery
*/
if ($typeobject == 'commande' && $expedition->origin_id > 0 && !empty($conf->commande->enabled))
{
if ($typeobject == 'commande' && $expedition->origin_id > 0 && !empty($conf->commande->enabled)) {
$objectsrc = new Commande($db);
$objectsrc->fetch($expedition->origin_id);
}
if ($typeobject == 'propal' && $expedition->origin_id > 0 && !empty($conf->propal->enabled))
{
if ($typeobject == 'propal' && $expedition->origin_id > 0 && !empty($conf->propal->enabled)) {
$objectsrc = new Propal($db);
$objectsrc->fetch($expedition->origin_id);
}
@ -390,19 +383,18 @@ if ($action == 'create') // Create. Seems to no be used
// Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
print '<td colspan="3">';
print $object->ref;
print '</td></tr>';
print '<td colspan="3">';
print $object->ref;
print '</td></tr>';
// Client
print '<tr><td width="20%">'.$langs->trans("Customer").'</td>';
print '<td colspan="3">'.$soc->getNomUrl(1).'</td>';
print "</tr>";
*/
*/
// Document origine
if ($typeobject == 'commande' && $expedition->origin_id && !empty($conf->commande->enabled))
{
if ($typeobject == 'commande' && $expedition->origin_id && !empty($conf->commande->enabled)) {
print '<tr><td class="titlefield">'.$langs->trans("RefOrder").'</td>';
$order = new Commande($db);
$order->fetch($expedition->origin_id);
@ -411,8 +403,7 @@ if ($action == 'create') // Create. Seems to no be used
print "</td>\n";
print '</tr>';
}
if ($typeobject == 'propal' && $expedition->origin_id && !empty($conf->propal->enabled))
{
if ($typeobject == 'propal' && $expedition->origin_id && !empty($conf->propal->enabled)) {
$propal = new Propal($db);
$propal->fetch($expedition->origin_id);
print '<tr><td class="titlefield">'.$langs->trans("RefProposal").'</td>';
@ -433,11 +424,12 @@ if ($action == 'create') // Create. Seems to no be used
print $langs->trans('DateReceived');
print '</td>';
if ($action != 'editdate_delivery') print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_delivery&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
if ($action != 'editdate_delivery') {
print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editdate_delivery&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'), 1).'</a></td>';
}
print '</tr></table>';
print '</td><td colspan="2">';
if ($action == 'editdate_delivery')
{
if ($action == 'editdate_delivery') {
print '<form name="setdate_delivery" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="setdate_delivery">';
@ -451,19 +443,20 @@ if ($action == 'create') // Create. Seems to no be used
print '</tr>';
// Incoterms
if (!empty($conf->incoterm->enabled))
{
if (!empty($conf->incoterm->enabled)) {
print '<tr><td>';
print '<table width="100%" class="nobordernopadding"><tr><td>';
print $langs->trans('IncotermLabel');
print '<td><td class="right">';
if ($user->rights->expedition->delivery->creer) print '<a class="editfielda" href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
else print '&nbsp;';
if ($user->rights->expedition->delivery->creer) {
print '<a class="editfielda" href="'.DOL_URL_ROOT.'/delivery/card.php?id='.$object->id.'&action=editincoterm">'.img_edit().'</a>';
} else {
print '&nbsp;';
}
print '</td></tr></table>';
print '</td>';
print '<td colspan="3">';
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);
@ -473,25 +466,24 @@ if ($action == 'create') // Create. Seems to no be used
/* A delivery note should be just more properties of a shipment, so notes are on shipment
// Note Public
print '<tr><td>'.$langs->trans("NotePublic").'</td>';
print '<td colspan="3">';
print nl2br($object->note_public);
print "</td></tr>";
print '<tr><td>'.$langs->trans("NotePublic").'</td>';
print '<td colspan="3">';
print nl2br($object->note_public);
print "</td></tr>";
// Note Private
print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
print '<td colspan="3">';
print nl2br($object->note_private);
print "</td></tr>";
*/
print '<tr><td>'.$langs->trans("NotePrivate").'</td>';
print '<td colspan="3">';
print nl2br($object->note_private);
print "</td></tr>";
*/
// Statut
/*print '<tr><td>'.$langs->trans("Status").'</td>';
print '<td colspan="3">'.$object->getLibStatut(4)."</td>\n";
print '</tr>';*/
if (!$conf->expedition_bon->enabled && !empty($conf->stock->enabled))
{
if (!$conf->expedition_bon->enabled && !empty($conf->stock->enabled)) {
// Entrepot
$entrepot = new Entrepot($db);
$entrepot->fetch($object->entrepot_id);
@ -524,8 +516,7 @@ if ($action == 'create') // Create. Seems to no be used
print '<table class="noborder centpercent">';
if ($num_prod)
{
if ($num_prod) {
$i = 0;
print '<tr class="liste_titre">';
@ -534,29 +525,30 @@ if ($action == 'create') // Create. Seems to no be used
print '<td class="center">'.$langs->trans("QtyReceived").'</td>';
print "</tr>\n";
}
while ($i < $num_prod)
{
while ($i < $num_prod) {
$parameters = array('i' => $i, 'line' => $object->lines[$i], 'num' => $num_prod);
$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 '<tr class="oddeven">';
if ($object->lines[$i]->fk_product > 0)
{
if ($object->lines[$i]->fk_product > 0) {
$product = new Product($db);
$product->fetch($object->lines[$i]->fk_product);
// 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)) {
$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);
}
@ -570,22 +562,27 @@ if ($action == 'create') // Create. Seems to no be used
// Affiche ligne produit
$text = '<a href="'.DOL_URL_ROOT.'/product/card.php?id='.$object->lines[$i]->fk_product.'">';
if ($object->lines[$i]->fk_product_type == 1) $text .= img_object($langs->trans('ShowService'), 'service');
else $text .= img_object($langs->trans('ShowProduct'), 'product');
if ($object->lines[$i]->fk_product_type == 1) {
$text .= img_object($langs->trans('ShowService'), 'service');
} else {
$text .= img_object($langs->trans('ShowProduct'), 'product');
}
$text .= ' '.$object->lines[$i]->product_ref.'</a>';
$text .= ' - '.$label;
$description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($object->lines[$i]->description));
//print $description;
print $form->textwithtooltip($text, $description, 3, '', '', $i);
print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
if (!empty($conf->global->PRODUIT_DESC_IN_FORM))
{
if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) {
print (!empty($object->lines[$i]->description) && $object->lines[$i]->description != $object->lines[$i]->product_label) ? '<br>'.dol_htmlentitiesbr($object->lines[$i]->description) : '';
}
} else {
print "<td>";
if ($object->lines[$i]->fk_product_type == 1) $text = img_object($langs->trans('Service'), 'service');
else $text = img_object($langs->trans('Product'), 'product');
if ($object->lines[$i]->fk_product_type == 1) {
$text = img_object($langs->trans('Service'), 'service');
} else {
$text = img_object($langs->trans('Product'), 'product');
}
if (!empty($object->lines[$i]->label)) {
$text .= ' <strong>'.$object->lines[$i]->label.'</strong>';
@ -640,23 +637,18 @@ if ($action == 'create') // Create. Seems to no be used
* Boutons actions
*/
if ($user->socid == 0)
{
if ($user->socid == 0) {
print '<div class="tabsAction">';
if ($object->statut == 0 && $num_prod > 0)
{
if ($object->statut == 0 && $num_prod > 0) {
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate)))
{
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=valid">'.$langs->trans("Validate").'</a>';
}
}
if ($user->rights->expedition->delivery->supprimer)
{
if ($conf->expedition_bon->enabled)
{
if ($user->rights->expedition->delivery->supprimer) {
if ($conf->expedition_bon->enabled) {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;expid='.$object->origin_id.'&amp;action=delete&amp;token='.newToken().'&amp;backtopage='.urlencode(DOL_URL_ROOT.'/expedition/card.php?id='.$object->origin_id).'">'.$langs->trans("Delete").'</a>';
} else {
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=delete&amp;token='.newToken().'">'.$langs->trans("Delete").'</a>';
@ -670,7 +662,7 @@ if ($action == 'create') // Create. Seems to no be used
print '<table width="100%" cellspacing="2"><tr><td width="50%" valign="top">';
/*
* Documents generated
* Documents generated
*/
$objectref = dol_sanitizeFileName($object->ref);
@ -683,10 +675,9 @@ if ($action == 'create') // Create. Seems to no be used
print $formfile->showdocuments('delivery', $objectref, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
/*
* Linked object block (of linked shipment)
*/
if ($object->origin == 'expedition')
{
* Linked object block (of linked shipment)
*/
if ($object->origin == 'expedition') {
$shipment = new Expedition($db);
$shipment->fetch($object->origin_id);

View File

@ -31,8 +31,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/commonincoterm.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.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->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';
}
/**
@ -132,7 +136,9 @@ class Delivery extends CommonObject
dol_syslog("Delivery::create");
if (empty($this->model_pdf)) $this->model_pdf = $conf->global->DELIVERY_ADDON_PDF;
if (empty($this->model_pdf)) {
$this->model_pdf = $conf->global->DELIVERY_ADDON_PDF;
}
$error = 0;
@ -176,8 +182,7 @@ class Delivery extends CommonObject
dol_syslog("Delivery::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."delivery");
$numref = "(PROV".$this->id.")";
@ -188,10 +193,8 @@ class Delivery extends CommonObject
dol_syslog("Delivery::create", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if (!$conf->expedition_bon->enabled)
{
if ($resql) {
if (!$conf->expedition_bon->enabled) {
$commande = new Commande($this->db);
$commande->id = $this->commande_id;
$commande->fetch_lines();
@ -202,38 +205,33 @@ class Delivery extends CommonObject
* Inserting products into the database
*/
$num = count($this->lines);
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
$origin_id = $this->lines[$i]->origin_line_id;
if (!$origin_id) $origin_id = $this->lines[$i]->commande_ligne_id; // For backward compatibility
if (!$origin_id) {
$origin_id = $this->lines[$i]->commande_ligne_id; // For backward compatibility
}
if (!$this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description))
{
if (!$this->create_line($origin_id, $this->lines[$i]->qty, $this->lines[$i]->fk_product, $this->lines[$i]->description)) {
$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++;
}
if (!$conf->expedition_bon->enabled)
{
if (!$conf->expedition_bon->enabled) {
// TODO standardize status uniformiser les statuts
$ret = $this->setStatut(2, $this->origin_id, $this->origin);
if (!$ret)
{
if (!$ret) {
$error++;
}
}
}
if (!$error)
{
if (!$error) {
$this->db->commit();
return $this->id;
} else {
@ -281,13 +279,11 @@ class Delivery extends CommonObject
$sql .= $qty.")";
dol_syslog(get_class($this)."::create_line", LOG_DEBUG);
if (!$this->db->query($sql))
{
if (!$this->db->query($sql)) {
$error++;
}
if ($error == 0)
{
if ($error == 0) {
return 1;
}
}
@ -315,10 +311,8 @@ class Delivery extends CommonObject
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;
@ -346,7 +340,9 @@ class Delivery extends CommonObject
$this->label_incoterms = $obj->label_incoterms;
$this->db->free($result);
if ($this->statut == 0) $this->draft = 1;
if ($this->statut == 0) {
$this->draft = 1;
}
// Retrieve all extrafields
// fetch optionals attributes and labels
@ -354,8 +350,7 @@ class Delivery extends CommonObject
// Load lines
$result = $this->fetch_lines();
if ($result < 0)
{
if ($result < 0) {
return -3;
}
@ -390,15 +385,12 @@ class Delivery extends CommonObject
$error = 0;
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate)))
{
if (!empty($conf->global->DELIVERY_ADDON_NUMBER))
{
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) {
if (!empty($conf->global->DELIVERY_ADDON_NUMBER)) {
// Setting the command numbering module name
$modName = $conf->global->DELIVERY_ADDON_NUMBER;
if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php'))
{
if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php')) {
require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php';
$now = dol_now();
@ -408,8 +400,7 @@ class Delivery extends CommonObject
$soc = new Societe($this->db);
$soc->fetch($this->socid);
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) // empty should not happened, but when it occurs, the test save life
{
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$numref = $objMod->delivery_get_num($soc, $this);
} else {
$numref = $this->ref;
@ -424,11 +415,9 @@ class Delivery extends CommonObject
$sql .= " AND entity = ".$conf->entity;
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num > 0)
{
if ($num > 0) {
return 0;
}
}
@ -442,50 +431,47 @@ class Delivery extends CommonObject
$sql .= " AND fk_statut = 0";
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
dol_print_error($this->db);
$this->error = $this->db->lasterror();
$error++;
}
if (!$error && !$notrigger)
{
if (!$error && !$notrigger) {
// Call trigger
$result = $this->call_trigger('DELIVERY_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/receipt/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/receipt/".$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.'/receipt/'.$oldref;
$dirdest = $conf->expedition->dir_output.'/receipt/'.$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.'/receipt/'.$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;
@ -497,8 +483,7 @@ class Delivery extends CommonObject
}
// Set new ref and current status
if (!$error)
{
if (!$error) {
$this->ref = $numref;
$this->statut = 1;
}
@ -506,8 +491,7 @@ class Delivery extends CommonObject
dol_syslog(get_class($this)."::valid ok");
}
if (!$error)
{
if (!$error) {
$this->db->commit();
return 1;
} else {
@ -540,8 +524,7 @@ class Delivery extends CommonObject
$this->lines = array();
$num = count($expedition->lines);
for ($i = 0; $i < $num; $i++)
{
for ($i = 0; $i < $num; $i++) {
$line = new DeliveryLine($this->db);
$line->origin_line_id = $expedition->lines[$i]->origin_line_id;
$line->label = $expedition->lines[$i]->label;
@ -583,22 +566,23 @@ class Delivery extends CommonObject
global $conf;
$error = 0;
if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) // For avoid conflicts if trigger used
{
if ($id > 0 && !$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($array_options) && count($array_options) > 0) { // For avoid conflicts if trigger used
$line = new DeliveryLine($this->db);
$line->array_options = $array_options;
$line->id = $id;
$result = $line->insertExtraFields();
if ($result < 0)
{
if ($result < 0) {
$this->error[] = $line->error;
$error++;
}
}
if (!$error) return 1;
else return -1;
if (!$error) {
return 1;
} else {
return -1;
}
}
@ -628,13 +612,11 @@ class Delivery extends CommonObject
*/
public function deleteline($lineid)
{
if ($this->statut == 0)
{
if ($this->statut == 0) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."commandedet";
$sql .= " WHERE rowid = ".$lineid;
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->update_price();
return 1;
@ -660,37 +642,31 @@ class Delivery extends CommonObject
$sql = "DELETE FROM ".MAIN_DB_PREFIX."deliverydet";
$sql .= " WHERE fk_delivery = ".$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++;
}
if (!$error)
{
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."delivery";
$sql .= " WHERE rowid = ".$this->id;
if ($this->db->query($sql))
{
if ($this->db->query($sql)) {
$this->db->commit();
// Deleting pdf folder's draft On efface le repertoire de pdf provisoire
$ref = dol_sanitizeFileName($this->ref);
if (!empty($conf->expedition->dir_output))
{
if (!empty($conf->expedition->dir_output)) {
$dir = $conf->expedition->dir_output.'/receipt/'.$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($dir))
{
if (file_exists($dir)) {
if (!dol_delete_dir($dir)) {
$this->error = $langs->trans("ErrorCanNotDeleteDir", $dir);
return 0;
}
@ -699,8 +675,7 @@ class Delivery extends CommonObject
// Call trigger
$result = $this->call_trigger('DELIVERY_DELETE', $user);
if ($result < 0)
{
if ($result < 0) {
$this->db->rollback();
return -4;
}
@ -746,16 +721,24 @@ class Delivery extends CommonObject
//{
// 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';
}
//}
$linkstart = '<a href="'.$url.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>';
if ($withpicto) $result .= ($linkstart.img_object($label, $this->picto, 'class="classfortooltip"').$linkend);
if ($withpicto && $withpicto != 2) $result .= ' ';
if ($withpicto) {
$result .= ($linkstart.img_object($label, $this->picto, 'class="classfortooltip"').$linkend);
}
if ($withpicto && $withpicto != 2) {
$result .= ' ';
}
$result .= $linkstart.$this->ref.$linkend;
return $result;
}
@ -782,12 +765,10 @@ class Delivery extends CommonObject
dol_syslog(get_class($this)."::fetch_lines", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
while ($i < $num) {
$line = new DeliveryLine($this->db);
$obj = $this->db->fetch_object($resql);
@ -862,8 +843,7 @@ class Delivery extends CommonObject
// phpcs:enable
global $langs;
if (empty($this->labelStatus) || empty($this->labelStatusShort))
{
if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
global $langs;
//$langs->load("mymodule");
$this->labelStatus[-1] = $langs->trans('StatusDeliveryCanceled');
@ -875,8 +855,12 @@ class Delivery extends CommonObject
}
$statusType = 'status0';
if ($status == -1) $statusType = 'status5';
if ($status == 1) $statusType = 'status4';
if ($status == -1) {
$statusType = 'status5';
}
if ($status == 1) {
$statusType = 'status4';
}
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
}
@ -905,12 +889,10 @@ class Delivery extends CommonObject
$sql .= $this->db->plimit(100);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num_prods = $this->db->num_rows($resql);
$i = 0;
while ($i < $num_prods)
{
while ($i < $num_prods) {
$i++;
$row = $this->db->fetch_row($resql);
$prodids[$i] = $row[0];
@ -961,13 +943,11 @@ class Delivery extends CommonObject
$sqlSourceLine .= " WHERE fk_".$this->linked_object[0]['type']." = ".$this->linked_object[0]['linkid'];
$resultSourceLine = $this->db->query($sqlSourceLine);
if ($resultSourceLine)
{
if ($resultSourceLine) {
$num_lines = $this->db->num_rows($resultSourceLine);
$i = 0;
$resultArray = array();
while ($i < $num_lines)
{
while ($i < $num_lines) {
$objSourceLine = $this->db->fetch_object($resultSourceLine);
// Get lines of sources alread delivered
@ -985,10 +965,8 @@ class Delivery extends CommonObject
$result = $this->db->query($sql);
$row = $this->db->fetch_row($result);
if ($objSourceLine->qty - $row[1] > 0)
{
if ($row[0] == $objSourceLine->rowid)
{
if ($objSourceLine->qty - $row[1] > 0) {
if ($row[0] == $objSourceLine->rowid) {
$array[$i]['qty'] = $objSourceLine->qty - $row[1];
} else {
$array[$i]['qty'] = $objSourceLine->qty;
@ -996,8 +974,7 @@ class Delivery extends CommonObject
$array[$i]['ref'] = $objSourceLine->ref;
$array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
} elseif ($objSourceLine->qty - $row[1] < 0)
{
} elseif ($objSourceLine->qty - $row[1] < 0) {
$array[$i]['qty'] = $objSourceLine->qty - $row[1]." Erreur livraison !";
$array[$i]['ref'] = $objSourceLine->ref;
$array[$i]['label'] = $objSourceLine->label ? $objSourceLine->label : $objSourceLine->description;
@ -1021,16 +998,14 @@ class Delivery extends CommonObject
*/
public function setDeliveryDate($user, $delivery_date)
{
if ($user->rights->expedition->creer)
{
if ($user->rights->expedition->creer) {
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery";
$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 {