Skip to content

Commit

Permalink
Merge pull request #1458 from KreizIT/dluo_step4
Browse files Browse the repository at this point in the history
Dluo step4
  • Loading branch information
eldy committed Mar 13, 2014
2 parents 1b85f83 + 18e4703 commit 743b0f1
Show file tree
Hide file tree
Showing 6 changed files with 433 additions and 19 deletions.
16 changes: 16 additions & 0 deletions htdocs/core/lib/pdf.lib.php
Expand Up @@ -5,6 +5,7 @@
* Copyright (C) 2010-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -946,6 +947,7 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
$desc=(! empty($object->lines[$i]->desc)?$object->lines[$i]->desc:(! empty($object->lines[$i]->description)?$object->lines[$i]->description:''));
$ref_supplier=(! empty($object->lines[$i]->ref_supplier)?$object->lines[$i]->ref_supplier:(! empty($object->lines[$i]->ref_fourn)?$object->lines[$i]->ref_fourn:'')); // TODO Not yet saved for supplier invoices, only supplier orders
$note=(! empty($object->lines[$i]->note)?$object->lines[$i]->note:'');
$dbatch=(! empty($object->lines[$i]->detail_batch)?$object->lines[$i]->detail_batch:false);

if ($issupplierline) $prodser = new ProductFournisseur($db);
else $prodser = new Product($db);
Expand Down Expand Up @@ -1079,6 +1081,20 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
//print $libelleproduitservice;
}

if ($dbatch)
{
$format='day';
foreach ($dbatch as $detail)
{
$dte=array();
if ($detail->eatby) $dte[]=$outputlangs->transnoentitiesnoconv('printEatby',dol_print_date($detail->eatby, $format, false, $outputlangs));
if ($detail->sellby) $dte[]=$outputlangs->transnoentitiesnoconv('printSellby',dol_print_date($detail->sellby, $format, false, $outputlangs));
if ($detail->batch) $dte[]=$outputlangs->transnoentitiesnoconv('printBatch',$detail->batch);
$dte[]=$outputlangs->transnoentitiesnoconv('printQty',$detail->dluo_qty);
$libelleproduitservice.= "__N__ ".implode($dte,"-");
}
}

// Now we convert \n into br
if (dol_textishtml($libelleproduitservice)) $libelleproduitservice=preg_replace('/__N__/','<br>',$libelleproduitservice);
else $libelleproduitservice=preg_replace('/__N__/',"\n",$libelleproduitservice);
Expand Down
88 changes: 86 additions & 2 deletions htdocs/expedition/class/expedition.class.php
Expand Up @@ -5,6 +5,7 @@
* Copyright (C) 2006-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -29,6 +30,7 @@
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.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->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionbatch.class.php';


/**
Expand Down Expand Up @@ -241,10 +243,17 @@ function create($user)
$num=count($this->lines);
for ($i = 0; $i < $num; $i++)
{
if (! isset($this->lines[$i]->detail_batch)) {
if (! $this->create_line($this->lines[$i]->entrepot_id, $this->lines[$i]->origin_line_id, $this->lines[$i]->qty) > 0)
{
$error++;
}
} else {
if (! $this->create_line_ext($this->lines[$i]) > 0)
{
$error++;
}
}
}

if (! $error && $this->id && $this->origin_id)
Expand Down Expand Up @@ -333,6 +342,31 @@ function create_line($entrepot_id, $origin_line_id, $qty)
if (! $error) return 1;
else return -1;
}
/**
* Create a expedition line with eat-by date
*
* @param object $line_ext full line informations
* @return int <0 if KO, >0 if OK
*/
function create_line_ext($line_ext)
{
$error = 0;

if ( $this->create_line(($line_ext->entrepot_id?$line_ext->entrepot_id:'null'),$line_ext->origin_line_id,$line_ext->qty)<0)
{
$error++;
} else {
$line_id= $this->db->last_insert_id(MAIN_DB_PREFIX."expeditiondet");
$tab=$line_ext->detail_batch;
foreach ($tab as $detbatch) {
if (! ($detbatch->create($line_id) >0)) {
$error++;
}
}
}
if (! $error) return 1;
else return -1;
}

/**
* Get object and lines from database
Expand Down Expand Up @@ -528,7 +562,7 @@ function valid($user)

// Loop on each product line to add a stock movement
// TODO possibilite d'expedier a partir d'une propale ou autre origine
$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot";
$sql = "SELECT cd.fk_product, cd.subprice, ed.qty, ed.fk_entrepot, ed.rowid";
$sql.= " FROM ".MAIN_DB_PREFIX."commandedet as cd,";
$sql.= " ".MAIN_DB_PREFIX."expeditiondet as ed";
$sql.= " WHERE ed.fk_expedition = ".$this->id;
Expand All @@ -550,6 +584,14 @@ function valid($user)
// We use warehouse selected for each line
$result=$mouvS->livraison($user, $obj->fk_product, $obj->fk_entrepot, $obj->qty, $obj->subprice, $langs->trans("ShipmentValidatedInDolibarr",$numref));
if ($result < 0) { $error++; break; }

if (! empty($conf->productbatch->enabled)) {
$details=ExpeditionLigneBatch::FetchAll($this->db,$obj->rowid);
foreach ($details as $dbatch) {
$result=$mouvS->livraison_batch($dbatch->fk_origin_stock,$dbatch->dluo_qty);
if ($result < 0) { $error++; $this->errors[]=$mouvS->$error; break 2; }
}
}
}
}
else
Expand Down Expand Up @@ -678,6 +720,38 @@ function addline($entrepot_id, $id, $qty)
$this->lines[$num] = $line;
}

/**
* Add a shipment line with batch record
*
* @param array $dbatch Array of value (key 'detail' -> Array, key 'qty' total quantity for line, key ix_l : original line index)
* @return int <0 if KO, >0 if OK
*/
function addline_batch($dbatch)
{
$num = count($this->lines);
if ($dbatch['qty']>0) {
$line = new ExpeditionLigne($this->db);
$tab=array();
foreach ($dbatch['detail'] as $key=>$value) {
if ($value['q']>0) {
$linebatch = new ExpeditionLigneBatch($this->db);
$ret=$linebatch->fetchFromStock($value['id_batch']);
if ($ret<0) {
$this->error=$linebatch->error;
return -1;
}
$linebatch->dluo_qty=$value['q'];
$tab[]=$linebatch;
}
}
$line->entrepot_id = $linebatch->entrepot_id;
$line->origin_line_id = $dbatch['ix_l'];
$line->qty = $dbatch['qty'];
$line->detail_batch=$tab;
$this->lines[$num] = $line;
}
}

/**
* Update database
*
Expand Down Expand Up @@ -798,6 +872,10 @@ function delete()

$this->db->begin();

if ($conf->productbatch->enabled) {
if ( ExpeditionLigneBatch::deletefromexp($this->db,$this->id)<0)
{$error++;$this->errors[]="Error ".$this->db->lasterror();}
}
// Stock control
if ($conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SHIPMENT && $this->statut > 0)
{
Expand Down Expand Up @@ -928,14 +1006,15 @@ function delete()
*/
function fetch_lines()
{
global $conf;
// TODO: recuperer les champs du document associe a part

$sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked";
$sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva";
$sql.= ", cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.price, cd.subprice, cd.remise_percent";
$sql.= ", ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot";
$sql.= ", p.ref as product_ref, p.label as product_label, p.fk_product_type";
$sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units";
$sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, ed.rowid as line_id";
$sql.= " FROM (".MAIN_DB_PREFIX."expeditiondet as ed,";
$sql.= " ".MAIN_DB_PREFIX."commandedet as cd)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = cd.fk_product";
Expand Down Expand Up @@ -1006,6 +1085,10 @@ function fetch_lines()
$this->total_localtax1+= $tabprice[9];
$this->total_localtax2+= $tabprice[10];

// Eat-by date
if (! empty($conf->productbatch->enabled)) {
$line->detail_batch=ExpeditionLigneBatch::FetchAll($this->db,$obj->line_id);
}
$this->lines[$i] = $line;

$i++;
Expand Down Expand Up @@ -1412,6 +1495,7 @@ class ExpeditionLigne
var $qty;
var $qty_shipped;
var $fk_product;
var $detail_batch;

// From llx_commandedet or llx_propaldet
var $qty_asked;
Expand Down

0 comments on commit 743b0f1

Please sign in to comment.