diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index fb45993f567..62fdcd89dc1 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -40,10 +40,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.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->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; -if (! empty($conf->stock->enabled)) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.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'; @@ -75,6 +75,7 @@ $result=restrictedArea($user, $origin, $origin_id); $action = GETPOST('action','alpha'); $confirm = GETPOST('confirm','alpha'); +$cancel = GETPOST('cancel','alpha'); //PDF $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); @@ -112,6 +113,8 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { + if ($cancel) { $action = ''; } + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once // Set incoterm @@ -127,6 +130,23 @@ if (empty($reshook)) $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); } + if ($action == 'setref_customer') + { + $result = $object->fetch($id); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + + $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer','alpha'), '', null, 'text', '', $user, 'SHIPMENT_MODIFY'); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + $action = 'editref_customer'; + } else { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + } + if ($action == 'update_extras') { // Fill array 'array_options' with data from update form @@ -566,9 +586,12 @@ llxHeader('',$langs->trans('Shipment'),'Expedition'); $form = new Form($db); $formfile = new FormFile($db); $formproduct = new FormProduct($db); -$product_static = new Product($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') { print load_fiche_titre($langs->trans("CreateASending")).'
'; @@ -1215,11 +1238,12 @@ else if ($id || $ref) if ($object->id > 0) { - if (!empty($object->origin)) + if (!empty($object->origin) && $object->origin_id > 0) { $typeobject = $object->origin; $origin = $object->origin; - $object->fetch_origin(); + $origin_id = $object->origin_id; + $object->fetch_origin(); // Load property $object->commande, $object->propal, ... } $soc = new Societe($db); @@ -1232,17 +1256,13 @@ else if ($id || $ref) $formconfirm=''; - /* - * Confirmation de la suppression - */ + // Confirm deleteion if ($action == 'delete') { $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('DeleteSending'),$langs->trans("ConfirmDeleteSending",$object->ref),'confirm_delete','',0,1); } - /* - * Confirmation de la validation - */ + // Confirmation validation if ($action == 'valid') { $objectref = substr($object->ref, 1, 4); @@ -1268,9 +1288,7 @@ else if ($id || $ref) $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('ValidateSending'),$text,'confirm_valid','',0,1); } - /* - * Confirmation de l'annulation - */ + // Confirm cancelation if ($action == 'annuler') { $formconfirm=$form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('CancelSending'),$langs->trans("ConfirmCancelSending",$object->ref),'confirm_cancel','',0,1); @@ -1295,21 +1313,30 @@ else if ($id || $ref) $totalVolume=$tmparray['volume']; + 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); + } + // Shipment card $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref='
'; // Ref customer shipment - $morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1); - $morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1); + $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); // Project - /* if (! empty($conf->projet->enabled)) { $langs->load("projects"); $morehtmlref .= '
' . $langs->trans('Project') . ' '; - if ($user->rights->supplier_proposal->creer) { + if (0) { // Do not change on shipment if ($action != 'classify') { $morehtmlref .= '' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; } @@ -1325,20 +1352,21 @@ else if ($id || $ref) $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1); } } else { - if (! empty($object->fk_project)) { + $morehtmlref .= ' : '; + if (! empty($objectsrc->fk_project)) { $proj = new Project($db); - $proj->fetch($object->fk_project); - $morehtmlref .= ''; + $proj->fetch($objectsrc->fk_project); + $morehtmlref .= ''; $morehtmlref .= $proj->ref; $morehtmlref .= ''; } else { $morehtmlref .= ''; } } - }*/ + } $morehtmlref.='
'; - + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); @@ -1352,8 +1380,6 @@ else if ($id || $ref) if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled)) { print ''; - $objectsrc=new Commande($db); - $objectsrc->fetch($object->$typeobject->id); print $langs->trans("RefOrder").''; print ''; print $objectsrc->getNomUrl(1,'commande'); @@ -1363,8 +1389,6 @@ else if ($id || $ref) if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled)) { print ''; - $objectsrc=new Propal($db); - $objectsrc->fetch($object->$typeobject->id); print $langs->trans("RefProposal").''; print ''; print $objectsrc->getNomUrl(1,'expedition'); @@ -1505,11 +1529,6 @@ else if ($id || $ref) print "\n"; print ''; - // Status - /*print ''.$langs->trans("Status").''; - print ''.$object->getLibStatut(4)."\n"; - print '';*/ - // Other attributes $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; @@ -1612,6 +1631,11 @@ else if ($id || $ref) print ''.$langs->trans("QtyShipped").''; } + if ($origin && $origin_id > 0) + { + print ''.$langs->trans("QtyInOtherShipments").''; + } + print ''.$langs->trans("CalculatedWeight").''; print ''.$langs->trans("CalculatedVolume").''; //print ''.$langs->trans("Size").''; @@ -1644,6 +1668,50 @@ else if ($id || $ref) } } + // Get list of products already sent for same source object + $alreadysent = array(); + 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,"; + //if ($conf->livraison_bon->enabled) $sql .= " l.rowid as livraison_id, l.ref as livraison_ref, l.date_delivery, ld.qty as qty_received,"; + $sql.= ' p.label as product_label, p.ref, p.fk_product_type, p.rowid as prodid,'; + $sql.= ' p.description as product_desc'; + $sql.= " FROM ".MAIN_DB_PREFIX."expeditiondet as ed"; + $sql.= ", ".MAIN_DB_PREFIX."expedition as e"; + $sql.= ", ".MAIN_DB_PREFIX.$origin."det as obj"; + //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; + $sql.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; + $sql.= " AND obj.fk_".$origin." = ".$origin_id; + $sql.= " AND obj.rowid = ed.fk_origin_line"; + $sql.= " AND ed.fk_expedition = e.rowid"; + //if ($filter) $sql.= $filter; + $sql.= " ORDER BY obj.fk_product"; + + dol_syslog("show_list_sending_receive", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + while($i < $num) + { + $obj = $db->fetch_object($resql); + 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, 'date_valid'=>$obj->date_valid, 'date_delivery'=>$obj->date_delivery); + } + $i++; + } + } + //var_dump($alreadysent); + } + + // Loop on each product to send/sent for ($i = 0 ; $i < $num_prod ; $i++) { print ""; @@ -1700,12 +1768,43 @@ else if ($id || $ref) print "\n"; } - // Qte commande + // Qty ordered print ''.$lines[$i]->qty_asked.''; - // Qte a expedier ou expedier + // Qty to ship or shipped print ''.$lines[$i]->qty_shipped.''; + // Qty in other shipments (with shipment and warehouse used) + if ($origin && $origin_id > 0) + { + print ''; + foreach ($alreadysent as $key => $val) + { + if ($lines[$i]->fk_origin_line == $key) + { + $j = 0; + foreach($val as $shipmentline_id=> $shipmentline_var) + { + if ($shipmentline_id == $lines[$i]->rowid) continue; // We want to show only "other shipments" + + $j++; + 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").' : '.dol_print_date($shipmentline_var['date_valid'], 'dayhour'); + if (! empty($conf->stock->enabled) && $shipmentline_var['warehouse'] > 0) + { + $warehousestatic->fetch($shipmentline_var['warehouse']); + $htmltext .= '
'.$langs->trans("From").' : '.$warehousestatic->getNomUrl(1); + } + print ' '.$form->textwithpicto('', $htmltext, 1); + } + } + } + } + print ''; + // Weight print ''; if ($lines[$i]->fk_product_type == 0) print $lines[$i]->weight*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->weight_units,"weight"); @@ -1721,7 +1820,7 @@ else if ($id || $ref) // Size //print ''.$lines[$i]->volume*$lines[$i]->qty_shipped.' '.measuring_units_string($lines[$i]->volume_units,"volume").''; - // Entrepot source + // Warehouse source if (! empty($conf->stock->enabled)) { print ''; @@ -1774,7 +1873,7 @@ else if ($id || $ref) } print ""; - //Display lines extrafields + // Display lines extrafields if (is_array($extralabelslines) && count($extralabelslines)>0) { $colspan= empty($conf->productbatch->enabled) ? 5 : 6; $line = new ExpeditionLigne($db); @@ -1787,6 +1886,10 @@ else if ($id || $ref) $var=!$var; } + // TODO Show also lines ordered but not delivered + + + print "\n"; } @@ -1796,6 +1899,7 @@ else if ($id || $ref) $object->fetchObjectLinked($object->id,$object->element); + /* * Boutons actions */ @@ -1885,6 +1989,7 @@ else if ($id || $ref) /* * Documents generated */ + if ($action != 'presend') { print '
'; @@ -1915,9 +2020,11 @@ else if ($id || $ref) print '
'; } + /* * Action presend */ + //Select mail models is same action as presend if (GETPOST('modelselected')) { $action = 'presend'; @@ -2049,13 +2156,6 @@ else if ($id || $ref) dol_fiche_end(); } - - if ($action != 'presend' && ! empty($origin) && $object->$origin->id) - { - print '
'; - //show_list_sending_receive($object->origin,$object->origin_id," AND e.rowid <> ".$object->id); - show_list_sending_receive($object->origin,$object->origin_id); - } } diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql index 098b91bb760..f604d518204 100644 --- a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -36,6 +36,7 @@ ALTER TABLE llx_facture_fourn_det ADD INDEX idx_facture_fourn_det_fk_code_ventil ALTER TABLE llx_facture_fourn_det ADD INDEX idx_facture_fourn_det_fk_product (fk_product); ALTER TABLE llx_facture_rec ADD COLUMN fk_user_modif integer; +ALTER TABLE llx_expedition ADD COLUMN fk_user_modif integer; ALTER TABLE llx_adherent ADD COLUMN model_pdf varchar(255); diff --git a/htdocs/install/mysql/tables/llx_expedition.sql b/htdocs/install/mysql/tables/llx_expedition.sql index 12dba35f89d..aa71e62c0a2 100644 --- a/htdocs/install/mysql/tables/llx_expedition.sql +++ b/htdocs/install/mysql/tables/llx_expedition.sql @@ -32,11 +32,12 @@ create table llx_expedition ref_customer varchar(30), -- customer number date_creation datetime, -- date de creation - fk_user_author integer, -- createur + fk_user_author integer, -- author of creation + fk_user_modif integer, -- author of last change date_valid datetime, -- date de validation fk_user_valid integer, -- valideur - date_expedition datetime, -- shipping date - date_delivery datetime DEFAULT NULL, -- delivery date + date_delivery datetime DEFAULT NULL, -- date planned of delivery + date_expedition datetime, -- not used (deprecated) fk_address integer DEFAULT NULL, -- delivery address (deprecated) fk_shipping_method integer, tracking_number varchar(50),