From 513b46e1d4a6edeed91e9ccc8b0f2ce7bdc5dd9d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 24 Feb 2016 13:19:25 +0100 Subject: [PATCH] NEW Can reopen an closed shipment --- htdocs/expedition/card.php | 98 +++++++++++--------- htdocs/expedition/class/expedition.class.php | 28 +++++- 2 files changed, 81 insertions(+), 45 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 8238f76ad9b..b0bdbf75af3 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -102,40 +102,6 @@ $permissiondellink=$user->rights->expedition->livraison->creer; // Used by the i * Actions */ - -// Set incoterm -if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) -{ - $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); -} - -if ($action == 'update_extras') -{ - // Fill array 'array_options' with data from update form - $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) $error++; - - if (! $error) - { - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - $hookmanager->initHooks(array('expeditiondao')); - $parameters = array('id' => $object->id); - $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - if (empty($reshook)) { - $result = $object->insertExtraFields(); - if ($result < 0) { - $error++; - } - } else if ($reshook < 0) - $error++; - } - - if ($error) - $action = 'edit_extras'; -} - $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'); @@ -144,6 +110,46 @@ if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once + // Set incoterm + if ($action == 'reopen' && $user->rights->expedition->creer) + { + $object->fetch($id); + $result = $object->reOpen(); + } + + // Set incoterm + if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled)) + { + $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); + } + + if ($action == 'update_extras') + { + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); + if ($ret < 0) $error++; + + if (! $error) + { + // Actions on extra fields (by external module or standard code) + // TODO le hook fait double emploi avec le trigger !! + $hookmanager->initHooks(array('expeditiondao')); + $parameters = array('id' => $object->id); + $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks + if (empty($reshook)) { + $result = $object->insertExtraFields(); + if ($result < 0) { + $error++; + } + } else if ($reshook < 0) + $error++; + } + + if ($error) + $action = 'edit_extras'; + } + if ($action == 'add' && $user->rights->expedition->creer) { $error=0; @@ -339,7 +345,7 @@ if (empty($reshook)) } else { - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToShip")), null, 'errors'); + setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("QtyToShip").'/'.$langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; } @@ -1108,9 +1114,9 @@ if ($action == 'create') } } } - if ($subj == 0) // Line not shown yet + if ($subj == 0) // Line not shown yet, we show it { - print ''; + print ''; if ($line->product_type == 0 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) { //$disabled='disabled="disabled"'; @@ -1358,7 +1364,9 @@ else if ($id || $ref) print ''; // Weight - print ''.$form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer).''; + print ''; + print $form->editfieldkey("Weight",'trueWeight',$object->trueWeight,$object,$user->rights->expedition->creer); + print ''; if ($action=='edittrueWeight') { @@ -1379,10 +1387,12 @@ else if ($id || $ref) print ($object->trueWeight && $object->weight_units!='')?' '.measuring_units_string($object->weight_units,"weight"):''; } + // Calculated if ($totalWeight > 0) { if (!empty($object->trueWeight)) print ' ('.$langs->trans("SumOfProductWeights").': '; print $totalWeight.' '.measuring_units_string(0,"weight"); + //if (empty($object->trueWeight)) print ' ('.$langs->trans("Calculated").')'; if (!empty($object->trueWeight)) print ')'; } print ''; @@ -1412,10 +1422,8 @@ else if ($id || $ref) { print $object->trueHeight; print ($object->trueHeight && $object->height_units!='')?' '.measuring_units_string($object->height_units,"size"):''; - } - print ''; // Depth @@ -1442,6 +1450,7 @@ else if ($id || $ref) { if ($calculatedVolume) print ' ('.$langs->trans("SumOfProductVolumes").': '; print $totalVolume.' '.measuring_units_string(0,"volume"); + //if (empty($calculatedVolume)) print ' ('.$langs->trans("Calculated").')'; if ($calculatedVolume) print ')'; } print "\n"; @@ -1743,11 +1752,12 @@ else if ($id || $ref) } // TODO add alternative status - /* if ($object->statut == 1 && $user->rights->expedition->creer) + // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order) + if ($object->statut == 2 && $object->billed && $user->rights->expedition->creer) { - print ''.$langs->trans("ReOpen").''; - }*/ - + print ''.$langs->trans("ReOpen").''; + } + // Send if ($object->statut > 0) { diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 9ccee64c8ab..62ffb53cc51 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1792,7 +1792,7 @@ class Expedition extends CommonObject $resql=$this->db->query($sql); if ($resql) { - //TODO: Option to set order billed if 100% of order is shipped + //TODO: Add option/checkbox to set order billed if 100% of order is shipped $this->statut=2; $this->billed=1; return 1; @@ -1804,6 +1804,32 @@ class Expedition extends CommonObject } } + /** + * Classify the shipping as validated/opened + * + * @return int <0 if ko, >0 if ok + */ + function reOpen() + { + global $conf; + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; + + $resql=$this->db->query($sql); + if ($resql) + { + $this->statut=1; + $this->billed=0; + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + /** * Create a document onto disk according to template module. *