diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 5fddccfa313..094a31bc06f 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3721,9 +3721,14 @@ abstract class CommonObject else if (! empty($line->fk_product)) { $productstatic = new Product($this->db); - $productstatic->id = $line->fk_product; + $productstatic->id = $line->fk_product; $productstatic->ref = $line->ref; $productstatic->type = $line->fk_product_type; + if(empty($productstatic->ref)){ + $line->fetch_product(); + $productstatic = $line->product; + } + $this->tpl['label'].= $productstatic->getNomUrl(1); $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); // Dates diff --git a/htdocs/core/modules/reception/mod_reception_beryl.php b/htdocs/core/modules/reception/mod_reception_beryl.php index 2b17d5ee0f0..49369f91c87 100644 --- a/htdocs/core/modules/reception/mod_reception_beryl.php +++ b/htdocs/core/modules/reception/mod_reception_beryl.php @@ -101,12 +101,12 @@ class mod_reception_beryl extends ModelNumRefReception { global $db,$conf; - $posindice=8; + $posindice=9; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."reception"; $sql.= " WHERE ref like '".$this->prefix."____-%'"; $sql.= " AND entity = ".$conf->entity; - + $resql=$db->query($sql); if ($resql) { diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 32379a18d60..d6aa7a1871d 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -1390,8 +1390,7 @@ if ($action == 'create') $projectid = $originid; $element = 'projet'; } - else if (in_array($element,array('order_supplier'))) - { + // For compatibility if ($element == 'order') { $element = $subelement = 'commande'; @@ -1412,6 +1411,18 @@ if ($action == 'create') $objectsrc = new $classname($db); $objectsrc->fetch($originid); $objectsrc->fetch_thirdparty(); + + if ($object->origin == 'reception') + { + $objectsrc->fetchObjectLinked(); + if (count($objectsrc->linkedObjectsIds['commande']) > 0) + { + foreach ($objectsrc->linkedObjectsIds['commande'] as $key => $value) + { + $object->linked_objects['commande'] = $value; + } + } + } $projectid = (!empty($objectsrc->fk_project)?$objectsrc->fk_project:''); //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:''); @@ -1438,8 +1449,9 @@ if ($action == 'create') // Replicate extrafields $objectsrc->fetch_optionals($originid); $object->array_options = $objectsrc->array_options; - } - } + + + } else { $cond_reglement_id = $societe->cond_reglement_supplier_id; @@ -1497,7 +1509,7 @@ if ($action == 'create') print ''; // Ref supplier - print ''.$langs->trans('RefSupplier').''; + print ''.$langs->trans('RefSupplier').''; print ''; // Type invoice @@ -1788,6 +1800,7 @@ if ($action == 'create') print ''.$langs->trans('NotePublic').''; print ''; $note_public = $object->getDefaultCreateValueFor('note_public'); + if(empty($note_public))$note_public = $objectsrc->note_public; $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); print ''; @@ -1798,6 +1811,8 @@ if ($action == 'create') print ''.$langs->trans('NotePrivate').''; print ''; $note_private = $object->getDefaultCreateValueFor('note_private'); + if(empty($note_private))$note_private = $objectsrc->note_private; + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); print ''; diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index 995d77b76a5..a462fb8e274 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -2147,22 +2147,17 @@ else if ($id || $ref) } // Create bill - if (! empty($conf->facture->enabled) && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED)) + if (! empty($conf->fournisseur->enabled) && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED)) { - if ($user->rights->facture->creer) + if ($user->rights->fournisseur->facture->creer) { // TODO show button only if (! empty($conf->global->WORKFLOW_BILL_ON_RECEPTION)) // If we do that, we must also make this option official. - print ''.$langs->trans("CreateBill").''; + print ''.$langs->trans("CreateBill").''; } } - // This is just to generate a delivery receipt - //var_dump($object->linkedObjectsIds['delivery']); - if ($conf->livraison_bon->enabled && ($object->statut == Reception::STATUS_VALIDATED || $object->statut == Reception::STATUS_CLOSED) && $user->rights->reception->livraison->creer && count($object->linkedObjectsIds['delivery']) == 0) - { - print ''.$langs->trans("CreateDeliveryOrder").''; - } + // Close if ($object->statut == Reception::STATUS_VALIDATED) { diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index 94028ec123e..fe6d24160fb 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -151,9 +151,10 @@ class Reception extends CommonObject } $obj = new $classname(); + $numref = ""; $numref = $obj->getNextValue($soc,$this); - + if ( $numref != "") { return $numref; @@ -498,7 +499,8 @@ class Reception extends CommonObject * Thirparty */ $result=$this->fetch_thirdparty(); - + + // Retrieve all extrafields for reception // fetch optionals attributes and labels require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; @@ -573,12 +575,13 @@ class Reception extends CommonObject // 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 - { + { $numref = $this->getNextNumRef($soc); } else { $numref = $this->ref; } + $this->newref = $numref; $now=dol_now(); @@ -590,7 +593,6 @@ class Reception extends CommonObject $sql.= ", date_valid = '".$this->db->idate($now)."'"; $sql.= ", fk_user_valid = ".$user->id; $sql.= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::valid update reception", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) @@ -1145,24 +1147,40 @@ class Reception extends CommonObject dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php'); $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch WHERE fk_reception='.$this->id; $resql = $db->query($sql); + if(!empty($resql)){ $this->lines = array(); while ($obj = $resql->fetch_object()){ $line = new CommandeFournisseurDispatch($db); $line->fetch($obj->rowid); $line->fetch_product(); - $sql_qtyasked = 'SELECT qty, description, label FROM llx_commande_fournisseurdet WHERE rowid='.$line->fk_commandefourndet; - $resql_qtyasked = $db->query($sql_qtyasked); - if(!empty($resql_qtyasked)){ - $obj = $db->fetch_object($resql_qtyasked); + $sql_commfourndet = 'SELECT qty, description, label, tva_tx, vat_src_code, subprice, multicurrency_subprice, remise_percent FROM llx_commande_fournisseurdet WHERE rowid='.$line->fk_commandefourndet; + $resql_commfourndet = $db->query($sql_commfourndet); + if(!empty($resql_commfourndet)){ + $obj = $db->fetch_object($resql_commfourndet); $line->qty_asked = $obj->qty; $line->description = $obj->description; + $line->desc = $obj->description; + $line->tva_tx = $obj->tva_tx; + $line->vat_src_code = $obj->vat_src_code; + $line->subprice = $obj->subprice; + $line->multicurrency_subprice = $obj->multicurrency_subprice; + $line->remise_percent = $obj->remise_percent; $line->label = $obj->label; }else { $line->qty_asked = 0; $line->description = ''; $line->label = $obj->label; } + + $pu_ht=($line->subprice*$line->qty)*(100-$line->remise_percent)/100; + $tva = $pu_ht*$line->tva_tx/100; + $this->total_ht += $pu_ht; + $this->total_tva += $pu_ht*$line->tva_tx/100; + + $this->total_ttc += $pu_ht+$tva; + + $this->lines[]=$line; } @@ -1283,7 +1301,7 @@ class Reception extends CommonObject function initAsSpecimen() { global $langs; - + dol_include_once('/fourn/class/fournisseur.commande.dispatch.class.php'); $now=dol_now(); dol_syslog(get_class($this)."::initAsSpecimen"); @@ -1339,7 +1357,7 @@ class Reception extends CommonObject $xnbp = 0; while ($xnbp < $nbp) { - $line=new ReceptionLigne($this->db); + $line=new CommandeFournisseurDispatch($this->db); $line->desc=$langs->trans("Description")." ".$xnbp; $line->libelle=$langs->trans("Description")." ".$xnbp; $line->qty=10; diff --git a/htdocs/reception/class/expeditionstats.class.php b/htdocs/reception/class/receptionstats.class.php similarity index 90% rename from htdocs/reception/class/expeditionstats.class.php rename to htdocs/reception/class/receptionstats.class.php index 7fa16f4210f..510bd4d8410 100644 --- a/htdocs/reception/class/expeditionstats.class.php +++ b/htdocs/reception/class/receptionstats.class.php @@ -19,20 +19,20 @@ */ /** - * \file htdocs/expedition/class/expeditionstats.class.php - * \ingroup expedition - * \brief File of class fo tmanage shipment statistics + * \file htdocs/reception/class/receptionstats.class.php + * \ingroup reception + * \brief File of class fo tmanage reception statistics */ include_once DOL_DOCUMENT_ROOT . '/core/class/stats.class.php'; -include_once DOL_DOCUMENT_ROOT . '/expedition/class/expedition.class.php'; +include_once DOL_DOCUMENT_ROOT . '/reception/class/reception.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; /** - * Class to manage shipment statistics + * Class to manage reception statistics */ -class ExpeditionStats extends Stats +class ReceptionStats extends Stats { public $table_element; @@ -62,7 +62,7 @@ class ExpeditionStats extends Stats $this->userid = $userid; $this->cachefilesuffix = $mode; - $object=new Expedition($this->db); + $object=new Reception($this->db); $this->from = MAIN_DB_PREFIX.$object->table_element." as c"; //$this->from.= ", ".MAIN_DB_PREFIX."societe as s"; $this->field='weight'; // Warning, unit of weight is NOT USED AND MUST BE @@ -79,7 +79,7 @@ class ExpeditionStats extends Stats } /** - * Return shipment number by month for a year + * Return reception number by month for a year * * @param int $year Year to scan * @return array Array with number by month @@ -101,7 +101,7 @@ class ExpeditionStats extends Stats } /** - * Return shipments number per year + * Return receptions number per year * * @return array Array with number by year * diff --git a/htdocs/reception/index.php b/htdocs/reception/index.php index 04fe5bc969a..cc4c891d5f1 100644 --- a/htdocs/reception/index.php +++ b/htdocs/reception/index.php @@ -183,7 +183,7 @@ $sql.= " ".MAIN_DB_PREFIX."societe as s"; 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 = ".$conf->entity; -$sql.= " AND c.fk_statut IN (3,4)"; +$sql.= " AND c.fk_statut IN (4)"; if ($socid) $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; diff --git a/htdocs/reception/stats/index.php b/htdocs/reception/stats/index.php index 53837c76fd1..a6f1f543c1d 100644 --- a/htdocs/reception/stats/index.php +++ b/htdocs/reception/stats/index.php @@ -18,14 +18,14 @@ */ /** - * \file htdocs/expedition/stats/index.php - * \ingroup expedition - * \brief Page with shipment statistics + * \file htdocs/reception/stats/index.php + * \ingroup reception + * \brief Page with reception statistics */ require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; -require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionstats.class.php'; +require_once DOL_DOCUMENT_ROOT.'/reception/class/reception.class.php'; +require_once DOL_DOCUMENT_ROOT.'/reception/class/receptionstats.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php'; $WIDTH=DolGraph::getDefaultGraphSizeForStats('width'); @@ -46,7 +46,7 @@ $year = GETPOST('year')>0?GETPOST('year'):$nowyear; $startyear=$year-1; $endyear=$year; -$langs->load("sendings"); +$langs->load("reception"); $langs->load("other"); $langs->load("companies"); @@ -59,12 +59,12 @@ $form=new Form($db); llxHeader(); -print load_fiche_titre($langs->trans("StatisticsOfSendings"), $mesg); +print load_fiche_titre($langs->trans("StatisticsOfReceptions"), $mesg); dol_mkdir($dir); -$stats = new ExpeditionStats($db, $socid, $mode, ($userid>0?$userid:0)); +$stats = new ReceptionStats($db, $socid, $mode, ($userid>0?$userid:0)); // Build graphic number of object $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); @@ -74,15 +74,15 @@ $data = $stats->getNbByMonthWithPrevYear($endyear,$startyear); if (!$user->rights->societe->client->voir || $user->societe_id) { - $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; - if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; - if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png'; + $filenamenb = $dir.'/receptionsnbinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstats&file=receptionsnbinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstatssupplier&file=receptionsnbinyear-'.$user->id.'-'.$year.'.png'; } else { - $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png'; - if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$year.'.png'; - if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$year.'.png'; + $filenamenb = $dir.'/receptionsnbinyear-'.$year.'.png'; + if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstats&file=receptionsnbinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstatssupplier&file=receptionsnbinyear-'.$year.'.png'; } $px1 = new DolGraph(); @@ -102,12 +102,12 @@ if (! $mesg) $px1->SetMinValue(min(0,$px1->GetFloorMinValue())); $px1->SetWidth($WIDTH); $px1->SetHeight($HEIGHT); - $px1->SetYLabel($langs->trans("NbOfSendings")); + $px1->SetYLabel($langs->trans("NbOfReceptions")); $px1->SetShading(3); $px1->SetHorizTickIncrement(1); $px1->SetPrecisionY(0); $px1->mode='depth'; - $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth")); + $px1->SetTitle($langs->trans("NumberOfReceptionsByMonth")); $px1->draw($filenamenb,$fileurlnb); } @@ -120,15 +120,15 @@ $data = $stats->getAmountByMonthWithPrevYear($endyear,$startyear); if (!$user->rights->societe->client->voir || $user->societe_id) { - $filenameamount = $dir.'/shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; - if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; - if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$user->id.'-'.$year.'.png'; + $filenameamount = $dir.'/receptionsamountinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstats&file=receptionsamountinyear-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstatssupplier&file=receptionsamountinyear-'.$user->id.'-'.$year.'.png'; } else { - $filenameamount = $dir.'/shipmentsamountinyear-'.$year.'.png'; - if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsamountinyear-'.$year.'.png'; - if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsamountinyear-'.$year.'.png'; + $filenameamount = $dir.'/receptionsamountinyear-'.$year.'.png'; + if ($mode == 'customer') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstats&file=receptionsamountinyear-'.$year.'.png'; + if ($mode == 'supplier') $fileurlamount = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstatssupplier&file=receptionsamountinyear-'.$year.'.png'; } $px2 = new DolGraph(); @@ -147,12 +147,12 @@ if (! $mesg) $px2->SetMinValue(min(0,$px2->GetFloorMinValue())); $px2->SetWidth($WIDTH); $px2->SetHeight($HEIGHT); - $px2->SetYLabel($langs->trans("AmountOfShipments")); + $px2->SetYLabel($langs->trans("AmountOfReceptions")); $px2->SetShading(3); $px2->SetHorizTickIncrement(1); $px2->SetPrecisionY(0); $px2->mode='depth'; - $px2->SetTitle($langs->trans("AmountOfShipmentsByMonthHT")); + $px2->SetTitle($langs->trans("AmountOfReceptionsByMonthHT")); $px2->draw($filenameamount,$fileurlamount); } @@ -163,15 +163,15 @@ $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear); if (!$user->rights->societe->client->voir || $user->societe_id) { - $filename_avg = $dir.'/shipmentsaverage-'.$user->id.'-'.$year.'.png'; - if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$user->id.'-'.$year.'.png'; - if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$user->id.'-'.$year.'.png'; + $filename_avg = $dir.'/receptionsaverage-'.$user->id.'-'.$year.'.png'; + if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstats&file=receptionsaverage-'.$user->id.'-'.$year.'.png'; + if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstatssupplier&file=receptionsaverage-'.$user->id.'-'.$year.'.png'; } else { - $filename_avg = $dir.'/shipmentsaverage-'.$year.'.png'; - if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsaverage-'.$year.'.png'; - if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsaverage-'.$year.'.png'; + $filename_avg = $dir.'/receptionsaverage-'.$year.'.png'; + if ($mode == 'customer') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstats&file=receptionsaverage-'.$year.'.png'; + if ($mode == 'supplier') $fileurl_avg = DOL_URL_ROOT.'/viewimage.php?modulepart=receptionstatssupplier&file=receptionsaverage-'.$year.'.png'; } $px3 = new DolGraph(); @@ -219,7 +219,7 @@ $head[$h][1] = $langs->trans("ByMonthYear"); $head[$h][2] = 'byyear'; $h++; -$type='shipment_stats'; +$type='reception_stats'; complete_head_from_modules($conf,$langs,null,$head,$h,$type); @@ -263,7 +263,7 @@ print '
'; print ''; print ''; print ''; -print ''; +print ''; /*print ''; print '';*/ print ''; @@ -289,7 +289,7 @@ foreach ($data as $val) print ''; print ''; print ''; /*print ''; @@ -328,10 +328,10 @@ dol_fiche_end(); /* print '
'.$langs->trans("Year").''.$langs->trans("NbOfSendings").''.$langs->trans("NbOfReceptions").''.$langs->trans("AmountTotal").''.$langs->trans("AmountAverage").'
'; if ($year) print ''.$year.''; - else print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated"); + else print $langs->trans("ValidationDateNotDefinedEvenIfReceptionValidated"); print ''.$val['nb'].''.price(price2num($val['total'],'MT'),1).'
'; print ''; -print ''; +print ''; -$sql = "SELECT count(*) as nb, date_format(date_expedition,'%Y') as dm"; -$sql.= " FROM ".MAIN_DB_PREFIX."expedition"; +$sql = "SELECT count(*) as nb, date_format(date_reception,'%Y') as dm"; +$sql.= " FROM ".MAIN_DB_PREFIX."reception"; $sql.= " WHERE fk_statut > 0"; $sql.= " AND entity = ".$conf->entity; $sql.= " GROUP BY dm DESC"; @@ -357,7 +357,7 @@ print '
'.$langs->trans("Year").''.$langs->trans("NbOfSendings").'
'.$langs->trans("NbOfReceptions").'
'; */ print '
'; -print ''.$langs->trans("StatsOnShipmentsOnlyValidated").''; +print ''.$langs->trans("StatsOnReceptionsOnlyValidated").''; llxFooter();