diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index c763ef19f84..058f8cb61c5 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1906,6 +1906,40 @@ class Commande extends CommonOrder return $nb; } + /** + * Count numbe rof shipments for this order + * + * @return int <0 if KO, Nb of shipment found if OK + */ + function getNbOfShipments() + { + $nb = 0; + + $sql = 'SELECT COUNT(DISTINCT ed.fk_expedition) as nb'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'expeditiondet as ed,'; + $sql.= ' '.MAIN_DB_PREFIX.'commandedet as cd'; + $sql.= ' WHERE'; + $sql.= ' ed.fk_origin_line = cd.rowid'; + $sql.= ' AND cd.fk_commande =' .$this->id; + //print $sql; + + dol_syslog(get_class($this)."::getNbOfShipments", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) + { + $obj = $this->db->fetch_object($resql); + if ($obj) $nb = $obj->nb; + + $this->db->free($resql); + return $nb; + } + else + { + $this->error=$this->db->lasterror(); + return -1; + } + } + /** * Load array this->expeditions of lines of shipments with nb of products sent for each order line * Note: For a dedicated shipment, the fetch_lines can be used to load the qty_asked and qty_shipped. This function is use to return qty_shipped cumulated for the order @@ -1932,18 +1966,18 @@ class Commande extends CommonOrder //print $sql; dol_syslog(get_class($this)."::loadExpeditions", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) + $resql = $this->db->query($sql); + if ($resql) { - $num = $this->db->num_rows($result); + $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { - $obj = $this->db->fetch_object($result); + $obj = $this->db->fetch_object($resql); $this->expeditions[$obj->rowid] = $obj->qty; $i++; } - $this->db->free(); + $this->db->free($resql); return $num; } else @@ -1951,7 +1985,6 @@ class Commande extends CommonOrder $this->error=$this->db->lasterror(); return -1; } - } /** @@ -2002,18 +2035,18 @@ class Commande extends CommonOrder $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; $sql.= " WHERE ps.fk_product IN (".join(',',$array_of_product).")"; $sql.= ' GROUP BY fk_product '; - $result = $this->db->query($sql); - if ($result) + $resql = $this->db->query($sql); + if ($resql) { - $num = $this->db->num_rows($result); + $num = $this->db->num_rows($resql); $i = 0; while ($i < $num) { - $obj = $this->db->fetch_object($result); + $obj = $this->db->fetch_object($resql); $this->stocks[$obj->fk_product] = $obj->total; $i++; } - $this->db->free(); + $this->db->free($resql); } } return 0; diff --git a/htdocs/core/lib/order.lib.php b/htdocs/core/lib/order.lib.php index 5d9f9280cc8..92a11c907d4 100644 --- a/htdocs/core/lib/order.lib.php +++ b/htdocs/core/lib/order.lib.php @@ -61,10 +61,13 @@ function commande_prepare_head(Commande $object) if (($conf->expedition_bon->enabled && $user->rights->expedition->lire) || ($conf->livraison_bon->enabled && $user->rights->expedition->livraison->lire)) { + $nbShipments=$object->getNbOfShipments(); $nbReceiption=0; $head[$h][0] = DOL_URL_ROOT.'/expedition/shipment.php?id='.$object->id; if ($conf->expedition_bon->enabled) $text=$langs->trans("Shipments"); + if ($nbShipments > 0) $text.= ' '.$nbShipments.''; if ($conf->expedition_bon->enabled && $conf->livraison_bon->enabled) $text.='/'; if ($conf->livraison_bon->enabled) $text.=$langs->trans("Receivings"); + if ($nbReceiption > 0) $text.= ' '.$nbReceiption.''; $head[$h][1] = $text; $head[$h][2] = 'shipping'; $h++; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index eb8c384e37e..44efbc46b15 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -607,13 +607,13 @@ if (empty($reshook)) $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 ($lines[$i]->id == $line_id) { - if (count($lines[$i]->details_entrepot) > 1) + if (count($lines[$i]->details_entrepot) > 1) { // delete multi warehouse lines foreach ($lines[$i]->details_entrepot as $details_entrepot) { @@ -624,7 +624,7 @@ if (empty($reshook)) } } } - else + else { // delete single warehouse line $line->id = $line_id; @@ -636,12 +636,12 @@ if (empty($reshook)) } unset($_POST["lineid"]); } - + if(! $error) { header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $object->id); exit(); } - else + else { setEventMessages($line->error, $line->errors, 'errors'); } @@ -657,12 +657,12 @@ if (empty($reshook)) $qty=0; $entrepot_id = 0; $batch_id = 0; - + $lines = $object->lines; $num_prod = count($lines); for ($i = 0 ; $i < $num_prod ; $i++) { - if ($lines[$i]->id == $line_id) + if ($lines[$i]->id == $line_id) { // line to update $line = new ExpeditionLigne($db); @@ -680,7 +680,7 @@ if (empty($reshook)) 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; @@ -689,13 +689,17 @@ if (empty($reshook)) $batch_qty = GETPOST($qty, 'int'); if (! empty($batch_id) && ($batch_id != $detail_batch->fk_origin_stock || $batch_qty != $detail_batch->dluo_qty)) { - if ($lotStock->fetch($batch_id) > 0 && $line->fetch($detail_batch->fk_expeditiondet) > 0) + 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(); + $line->detail_batch->fk_origin_stock = $batch_id; $line->detail_batch->batch = $lotStock->batch; $line->detail_batch->id = $detail_batch->id; @@ -706,7 +710,7 @@ if (empty($reshook)) $error++; } } - else + else { setEventMessages($lotStock->error, $lotStock->errors, 'errors'); $error++; @@ -716,7 +720,7 @@ if (empty($reshook)) unset($_POST[$qty]); } } - else + else { // line without lot if ($lines[$i]->entrepot_id > 0) @@ -782,7 +786,7 @@ if (empty($reshook)) $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } } - else + else { header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition exit(); @@ -1526,7 +1530,13 @@ if ($action == 'create') print ""; - print '
'; + print '
'; + + print '
'; + print ''; + print '     '; + print ''; + print '
'; print ''; @@ -1977,7 +1987,7 @@ else if ($id || $ref) } print ''; } - else + else { if ($object->statut <= 1) { @@ -1991,7 +2001,7 @@ else if ($id || $ref) { print ''.$langs->trans("WarehouseSource").''; } - + if (! empty($conf->productbatch->enabled)) { print ''.$langs->trans("Batch").''; @@ -2166,7 +2176,7 @@ else if ($id || $ref) if (is_array($lines[$i]->detail_batch) && count($lines[$i]->detail_batch) > 0) { $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 @@ -2320,7 +2330,7 @@ else if ($id || $ref) { print $line->showOptionals($extrafieldsline, 'edit', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked); } - else + else { print $line->showOptionals($extrafieldsline, 'view', array('style'=>$bc[$var], 'colspan'=>$colspan),$indiceAsked); } @@ -2480,136 +2490,6 @@ else if ($id || $ref) $trackid = 'shi'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; - - /* - if ($action == 'presend') - { - $ref = dol_sanitizeFileName($object->ref); - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'[^\-]+'); - $file=$fileparams['fullname']; - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) - $newlang = $_REQUEST['lang_id']; - if ($conf->global->MAIN_MULTILANGS && empty($newlang)) - $newlang = $object->thirdparty->default_lang; - - if (!empty($newlang)) - { - $outputlangs = new Translate('', $conf); - $outputlangs->setDefaultLang($newlang); - $outputlangs->load('sendings'); - } - - // Build document if it not exists - if (! $file || ! is_readable($file)) - { - $result = $object->generateDocument(GETPOST('model')?GETPOST('model'):$object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); - if ($result <= 0) - { - dol_print_error($db,$object->error,$object->errors); - exit; - } - $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'[^\-]+'); - $file=$fileparams['fullname']; - } - - print '
'; - print '
'; - print '
'; - print load_fiche_titre($langs->trans('SendShippingByEMail')); - - dol_fiche_head(''); - - // Cree l'objet formulaire mail - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); - $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user')); - - if($formmail->fromtype === 'user'){ - $formmail->fromid = $user->id; - - } - $formmail->trackid='shi'.$object->id; - if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set - { - include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'shi'.$object->id); - } - $formmail->withfrom=1; - $liste=array(); - foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key=>$value) $liste[$key]=$value; - $formmail->withto=GETPOST("sendto")?GETPOST("sendto"):$liste; - $formmail->withtocc=$liste; - $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; - $formmail->withtopic=$outputlangs->trans('SendShippingRef','__SHIPPINGREF__'); - $formmail->withfile=2; - $formmail->withbody=1; - $formmail->withdeliveryreceipt=1; - $formmail->withcancel=1; - // Tableau des substitutions - $formmail->setSubstitFromObject($object, $outputlangs); - $formmail->substit['__SHIPPINGREF__']=$object->ref; - $formmail->substit['__SHIPPINGTRACKNUM__']=$object->tracking_number; - $formmail->substit['__SHIPPINGTRACKNUMURL__']=$object->tracking_url; - - //Find the good contact adress - 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)) { - $objectsrc=new Propal($db); - $objectsrc->fetch($object->$typeobject->id); - } - $custcontact=''; - $contactarr=array(); - if (is_object($objectsrc)) // For the case the shipment was created without orders - { - $contactarr=$objectsrc->liste_contact(-1,'external'); - } - - if (is_array($contactarr) && count($contactarr)>0) { - foreach($contactarr as $contact) { - - if ($contact['libelle']==$langs->trans('TypeContact_commande_external_CUSTOMER')) { - - require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; - - $contactstatic=new Contact($db); - $contactstatic->fetch($contact['id']); - $custcontact=$contactstatic->getFullName($langs,1); - } - } - - if (!empty($custcontact)) { - $formmail->substit['__CONTACTCIVNAME__']=$custcontact; - } - } - - // Tableau des parametres complementaires - $formmail->param['action']='send'; - $formmail->param['models']='shipping_send'; - $formmail->param['models_id']=GETPOST('modelmailselected','int'); - $formmail->param['shippingid']=$object->id; - $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - - // Init list of files - if (GETPOST("mode")=='init') - { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); - } - - // Show form - print $formmail->get_form(); - - dol_fiche_end(); - }*/ } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 3e341e6d5be..872badf9220 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -2220,7 +2220,7 @@ class ExpeditionLigne extends CommonObjectLine */ public $fk_expedition; - var $db; + var $db; // From llx_expeditiondet var $qty; @@ -2232,7 +2232,7 @@ class ExpeditionLigne extends CommonObjectLine * @var int */ public $entrepot_id; - + // From llx_commandedet or llx_propaldet var $qty_asked; @@ -2249,7 +2249,7 @@ class ExpeditionLigne extends CommonObjectLine var $total_localtax1; // Total Local tax 1 var $total_localtax2; // Total Local tax 2 - + // Deprecated /** @@ -2395,7 +2395,7 @@ class ExpeditionLigne extends CommonObjectLine /** * Delete shipment line. - * + * * @param User $user User that modify * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int >0 if OK, <0 if KO @@ -2407,7 +2407,7 @@ class ExpeditionLigne extends CommonObjectLine $error=0; $this->db->begin(); - + // delete batch expedition line if ($conf->productbatch->enabled) { @@ -2420,7 +2420,7 @@ class ExpeditionLigne extends CommonObjectLine $error++; } } - + $sql = "DELETE FROM ".MAIN_DB_PREFIX."expeditiondet"; $sql.= " WHERE rowid = ".$this->id; @@ -2436,7 +2436,7 @@ class ExpeditionLigne extends CommonObjectLine $error++; } } - if (! $error && ! $notrigger) + if (! $error && ! $notrigger) { // Call trigger $result=$this->call_trigger('LINESHIPPING_DELETE',$user); @@ -2458,7 +2458,7 @@ class ExpeditionLigne extends CommonObjectLine $this->db->commit(); return 1; } - else + else { foreach($this->errors as $errmsg) { @@ -2469,10 +2469,10 @@ class ExpeditionLigne extends CommonObjectLine return -1*$error; } } - + /** * Update a line in database - * + * * @param User $user User that modify * @param int $notrigger 1 = disable triggers * @return int < 0 if KO, > 0 if OK @@ -2480,13 +2480,11 @@ class ExpeditionLigne extends CommonObjectLine function update($user = null, $notrigger = 0) { global $conf; - + $error=0; dol_syslog(get_class($this)."::update id=$this->id, entrepot_id=$this->entrepot_id, product_id=$this->fk_product, qty=$this->qty"); - - $this->db->begin(); // Clean parameters @@ -2496,9 +2494,9 @@ class ExpeditionLigne extends CommonObjectLine $batch = null; $batch_id = null; $expedition_batch_id = null; - if (is_array($this->detail_batch)) + if (is_array($this->detail_batch)) // array of ExpeditionLineBatch { - if (count($this->detail_batch) > 1) + if (count($this->detail_batch) > 1) { dol_syslog(get_class($this).'::update only possible for one batch', LOG_ERR); $this->errors[]='ErrorBadParameters'; @@ -2545,8 +2543,8 @@ class ExpeditionLigne extends CommonObjectLine if (! empty($batch) && $conf->productbatch->enabled) { - dol_syslog(get_class($this)."::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch"); - + dol_syslog(get_class($this)."::update expedition batch id=$expedition_batch_id, batch_id=$batch_id, batch=$batch"); + if (empty($batch_id) || empty($expedition_batch_id) || empty($this->fk_product)) { dol_syslog(get_class($this).'::update missing fk_origin_stock (batch_id) and/or fk_product', LOG_ERR); $this->errors[]='ErrorMandatoryParametersNotProvided'; @@ -2560,24 +2558,24 @@ class ExpeditionLigne extends CommonObjectLine $this->errors[]=$this->db->lasterror()." - ExpeditionLineBatch::fetchAll"; $error++; } - else + else { // caculate new total line qty - foreach ($lotArray as $lot) + foreach ($lotArray as $lot) { - if ($expedition_batch_id != $lot->id) + if ($expedition_batch_id != $lot->id) { $remainingQty += $lot->dluo_qty; } } $qty += $remainingQty; - + //fetch lot details - + // 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++; @@ -2588,15 +2586,15 @@ class ExpeditionLigne extends CommonObjectLine $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)) { $this->errors[]=$this->db->lasterror()." - sql=$sql"; $error++; } - else if ($qty > 0) + else if ($qty > 0) { - if (isset($lot->id)) + if (isset($lot->id)) { $shipmentLot = new ExpeditionLineBatch($this->db); $shipmentLot->batch = $lot->batch; @@ -2605,7 +2603,7 @@ class ExpeditionLigne extends CommonObjectLine $shipmentLot->entrepot_id = $this->detail_batch->entrepot_id; $shipmentLot->dluo_qty = $this->detail_batch->dluo_qty; $shipmentLot->fk_origin_stock = $batch_id; - if ($shipmentLot->create($this->id) < 0) + if ($shipmentLot->create($this->id) < 0) { $this->errors[]=$shipmentLot->errors; $error++; @@ -2622,8 +2620,8 @@ class ExpeditionLigne extends CommonObjectLine $sql.= " fk_entrepot = ".$this->entrepot_id; $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++; @@ -2641,7 +2639,7 @@ class ExpeditionLigne extends CommonObjectLine } } } - if (! $error && ! $notrigger) + if (! $error && ! $notrigger) { // Call trigger $result=$this->call_trigger('LINESHIPPING_UPDATE',$user); @@ -2656,7 +2654,7 @@ class ExpeditionLigne extends CommonObjectLine $this->db->commit(); return 1; } - else + else { foreach($this->errors as $errmsg) { diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 957d9864e16..0af347c0fb7 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -39,13 +39,7 @@ if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/st 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'; -$langs->load('orders'); -$langs->load("companies"); -$langs->load("bills"); -$langs->load('propal'); -$langs->load('deliveries'); -$langs->load('stocks'); -$langs->load("productbatch"); +$langs->loadLangs(array('orders',"companies","bills",'propal','deliveries','stocks',"productbatch",'incoterm')); $id=GETPOST('id','int'); // id of order $ref= GETPOST('ref','alpha'); @@ -528,7 +522,7 @@ if ($id > 0 || ! empty($ref)) print '
'; print $langs->trans('IncotermLabel'); print ''; - if ($user->rights->commande->creer) print ''.img_edit().''; + if ($user->rights->commande->creer) print ''.img_edit().''; else print ' '; print '
'; print ''; diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 0bc41779596..947a476c1de 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -447,7 +447,7 @@ input:-webkit-autofill { ::-moz-placeholder { color:#bbb; } /* firefox 19+ */ :-ms-input-placeholder { color:#ccc; } /* ie */ input:-moz-placeholder { color:#ccc; } -input[name=weight], input[name=volume], input[name=surface], input[name=sizeheight] { margin-right: 6px; } +input[name=weight], input[name=volume], input[name=surface], input[name=sizeheight], select[name=incoterm_id] { margin-right: 6px; } input[name=surface] { margin-right: 4px; } fieldset { border: 1px solid #AAAAAA !important; } .legendforfieldsetstep { padding-bottom: 10px; } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 061ab132f99..e8db7ef335b 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -457,7 +457,8 @@ input:-webkit-autofill { ::-moz-placeholder { color:#bbb; } /* firefox 19+ */ :-ms-input-placeholder { color:#ccc; } /* ie */ input:-moz-placeholder { color:#ccc; } - +input[name=weight], input[name=volume], input[name=surface], input[name=sizeheight], select[name=incoterm_id] { margin-right: 6px; } +input[name=surface] { margin-right: 4px; } fieldset { border: 1px solid #AAAAAA !important; } .legendforfieldsetstep { padding-bottom: 10px; }