Documented invoice types

This commit is contained in:
Marcos García de La Fuente 2014-02-25 00:46:04 +01:00
parent f537f62aea
commit e90f068e3b

View File

@ -67,8 +67,8 @@ class Facture extends CommonInvoice
var $ref_client;
var $ref_ext;
var $ref_int;
//! 0=Standard invoice, 1=Replacement invoice, 2=Credit note invoice, 3=Deposit invoice, 4=Proforma invoice
var $type=0;
//Check constants for types
var $type= self::TYPE_STANDARD;
//var $amount;
var $remise_absolue;
@ -116,6 +116,30 @@ class Facture extends CommonInvoice
var $fac_rec;
/**
* Standard invoice
*/
const TYPE_STANDARD = 0;
/**
* Replacement invoice
*/
const TYPE_REPLACEMENT = 1;
/**
* Credit note invoice
*/
const TYPE_CREDIT_NOTE = 2;
/**
* Deposit invoice
*/
const TYPE_DEPOSIT = 3;
/**
* Proforma invoice
*/
const TYPE_PROFORMA = 4;
/**
* Constructor
@ -142,7 +166,7 @@ class Facture extends CommonInvoice
$error=0;
// Clean parameters
if (empty($this->type)) $this->type = 0;
if (empty($this->type)) $this->type = self::TYPE_STANDARD;
$this->ref_client=trim($this->ref_client);
$this->note=(isset($this->note) ? trim($this->note) : trim($this->note_private)); // deprecated
$this->note_private=(isset($this->note_private) ? trim($this->note_private) : trim($this->note_private));
@ -187,7 +211,7 @@ class Facture extends CommonInvoice
$this->remise_percent = $_facrec->remise_percent;
// Clean parametres
if (! $this->type) $this->type = 0;
if (! $this->type) $this->type = self::TYPE_STANDARD;
$this->ref_client=trim($this->ref_client);
$this->note_private=trim($this->note_private);
$this->note_public=trim($this->note_public);
@ -765,14 +789,14 @@ class Facture extends CommonInvoice
if ($short) return $url;
$picto='bill';
if ($this->type == 1) $picto.='r'; // Replacement invoice
if ($this->type == 2) $picto.='a'; // Credit note
if ($this->type == 3) $picto.='d'; // Deposit invoice
if ($this->type == self::TYPE_REPLACEMENT) $picto.='r'; // Replacement invoice
if ($this->type == self::TYPE_CREDIT_NOTE) $picto.='a'; // Credit note
if ($this->type == self::TYPE_DEPOSIT) $picto.='d'; // Deposit invoice
$label=$langs->trans("ShowInvoice").': '.$this->ref;
if ($this->type == 1) $label=$langs->transnoentitiesnoconv("ShowInvoiceReplace").': '.$this->ref;
if ($this->type == 2) $label=$langs->transnoentitiesnoconv("ShowInvoiceAvoir").': '.$this->ref;
if ($this->type == 3) $label=$langs->transnoentitiesnoconv("ShowInvoiceDeposit").': '.$this->ref;
if ($this->type == self::TYPE_REPLACEMENT) $label=$langs->transnoentitiesnoconv("ShowInvoiceReplace").': '.$this->ref;
if ($this->type == self::TYPE_CREDIT_NOTE) $label=$langs->transnoentitiesnoconv("ShowInvoiceAvoir").': '.$this->ref;
if ($this->type == self::TYPE_DEPOSIT) $label=$langs->transnoentitiesnoconv("ShowInvoiceDeposit").': '.$this->ref;
if ($moretitle) $label.=' - '.$moretitle;
//$linkstart='<a href="'.$url.'" title="'.dol_escape_htmltag($label).'">';
@ -1016,7 +1040,7 @@ class Facture extends CommonInvoice
$error=0;
// Clean parameters
if (empty($this->type)) $this->type=0;
if (empty($this->type)) $this->type= self::TYPE_STANDARD;
if (isset($this->facnumber)) $this->facnumber=trim($this->ref);
if (isset($this->ref_client)) $this->ref_client=trim($this->ref_client);
if (isset($this->increment)) $this->increment=trim($this->increment);
@ -1294,7 +1318,7 @@ class Facture extends CommonInvoice
}
// If we decrament stock on invoice validation, we increment
if ($this->type != 3 && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse!=-1)
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $idwarehouse!=-1)
{
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
@ -1306,7 +1330,7 @@ class Facture extends CommonInvoice
{
$mouvP = new MouvementStock($this->db);
// We decrease stock for product
if ($this->type == 2) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr",$this->ref));
if ($this->type == self::TYPE_CREDIT_NOTE) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceDeleteDolibarr",$this->ref));
else $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceDeleteDolibarr",$this->ref)); // we use 0 for price, to not change the weighted average value
}
}
@ -1664,7 +1688,7 @@ class Facture extends CommonInvoice
$this->fetch_lines();
// Check parameters
if ($this->type == 1) // si facture de remplacement
if ($this->type == self::TYPE_REPLACEMENT) // si facture de remplacement
{
// Controle que facture source connue
if ($this->fk_facture_source <= 0)
@ -1758,7 +1782,7 @@ class Facture extends CommonInvoice
$result=$this->client->set_as_client();
// Si active on decremente le produit principal et ses composants a la validation de facture
if ($this->type != 3 && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
{
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
@ -1771,7 +1795,7 @@ class Facture extends CommonInvoice
{
$mouvP = new MouvementStock($this->db);
// We decrease stock for product
if ($this->type == 2) $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num));
if ($this->type == self::TYPE_CREDIT_NOTE) $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num));
else $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarr",$num));
if ($result < 0) {
$error++;
@ -1881,7 +1905,7 @@ class Facture extends CommonInvoice
if ($result)
{
// Si on decremente le produit principal et ses composants a la validation de facture, on réincrement
if ($this->type != 3 && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
if ($this->type != self::TYPE_DEPOSIT && $result >= 0 && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
{
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php';
$langs->load("agenda");
@ -1893,7 +1917,7 @@ class Facture extends CommonInvoice
{
$mouvP = new MouvementStock($this->db);
// We decrease stock for product
if ($this->type == 2) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr",$this->ref));
if ($this->type == self::TYPE_CREDIT_NOTE) $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr",$this->ref));
else $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("InvoiceBackToDraftInDolibarr",$this->ref)); // we use 0 for price, to not change the weighted average value
}
}
@ -1974,7 +1998,7 @@ class Facture extends CommonInvoice
* @param array $array_option extrafields array
* @return int <0 if KO, Id of line if OK
*/
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=0, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_option=0)
function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type= self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='',$array_option=0)
{
global $mysoc;
@ -2055,27 +2079,27 @@ class Facture extends CommonInvoice
$this->line->fk_facture=$facid;
$this->line->label=$label;
$this->line->desc=$desc;
$this->line->qty= ($this->type==2?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative
$this->line->qty= ($this->type==self::TYPE_CREDIT_NOTE?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative
$this->line->tva_tx=$txtva;
$this->line->localtax1_tx=$txlocaltax1;
$this->line->localtax2_tx=$txlocaltax2;
$this->line->fk_product=$fk_product;
$this->line->product_type=$product_type;
$this->line->remise_percent=$remise_percent;
$this->line->subprice= ($this->type==2?-abs($pu_ht):$pu_ht); // For credit note, unit price always negative, always positive otherwise
$this->line->subprice= ($this->type==self::TYPE_CREDIT_NOTE?-abs($pu_ht):$pu_ht); // For credit note, unit price always negative, always positive otherwise
$this->line->date_start=$date_start;
$this->line->date_end=$date_end;
$this->line->ventil=$ventil;
$this->line->rang=$rangtouse;
$this->line->info_bits=$info_bits;
$this->line->fk_remise_except=$fk_remise_except;
$this->line->total_ht= (($this->type==2||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative
$this->line->total_tva= (($this->type==2||$qty<0)?-abs($total_tva):$total_tva);
$this->line->total_localtax1=(($this->type==2||$qty<0)?-abs($total_localtax1):$total_localtax1);
$this->line->total_localtax2=(($this->type==2||$qty<0)?-abs($total_localtax2):$total_localtax2);
$this->line->total_ht= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative
$this->line->total_tva= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_tva):$total_tva);
$this->line->total_localtax1=(($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax1):$total_localtax1);
$this->line->total_localtax2=(($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax2):$total_localtax2);
$this->line->localtax1_type = $localtaxes_type[0];
$this->line->localtax2_type = $localtaxes_type[2];
$this->line->total_ttc= (($this->type==2||$qty<0)?-abs($total_ttc):$total_ttc);
$this->line->total_ttc= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ttc):$total_ttc);
$this->line->special_code=$special_code;
$this->line->fk_parent_line=$fk_parent_line;
$this->line->origin=$origin;
@ -2145,7 +2169,7 @@ class Facture extends CommonInvoice
* @param array $array_option extrafields array
* @return int < 0 if KO, > 0 if OK
*/
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_option=0)
function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_option=0)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
@ -2217,7 +2241,7 @@ class Facture extends CommonInvoice
$this->line->rowid = $rowid;
$this->line->label = $label;
$this->line->desc = $desc;
$this->line->qty = ($this->type==2?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative
$this->line->qty = ($this->type==self::TYPE_CREDIT_NOTE?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative
$this->line->tva_tx = $txtva;
$this->line->localtax1_tx = $txlocaltax1;
$this->line->localtax2_tx = $txlocaltax2;
@ -2227,11 +2251,11 @@ class Facture extends CommonInvoice
$this->line->subprice = ($this->type==2?-abs($pu_ht):$pu_ht); // For credit note, unit price always negative, always positive otherwise
$this->line->date_start = $date_start;
$this->line->date_end = $date_end;
$this->line->total_ht = (($this->type==2||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative
$this->line->total_tva = (($this->type==2||$qty<0)?-abs($total_tva):$total_tva);
$this->line->total_localtax1 = (($this->type==2||$qty<0)?-abs($total_localtax1):$total_localtax1);
$this->line->total_localtax2 = (($this->type==2||$qty<0)?-abs($total_localtax2):$total_localtax2);
$this->line->total_ttc = (($this->type==2||$qty<0)?-abs($total_ttc):$total_ttc);
$this->line->total_ht = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative
$this->line->total_tva = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_tva):$total_tva);
$this->line->total_localtax1 = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax1):$total_localtax1);
$this->line->total_localtax2 = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax2):$total_localtax2);
$this->line->total_ttc = (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ttc):$total_ttc);
$this->line->info_bits = $info_bits;
$this->line->special_code = $special_code;
$this->line->product_type = $type;
@ -2824,14 +2848,14 @@ class Facture extends CommonInvoice
$sql = "SELECT f.rowid as rowid, f.facnumber, f.fk_statut, f.type, f.paye, pf.fk_paiement";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON (f.rowid = ff.fk_facture_source AND ff.type=1)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as ff ON (f.rowid = ff.fk_facture_source AND ff.type=".self::TYPE_REPLACEMENT.")";
$sql.= " WHERE f.entity = ".$conf->entity;
$sql.= " AND f.fk_statut in (1,2)";
// $sql.= " WHERE f.fk_statut >= 1";
// $sql.= " AND (f.paye = 1"; // Classee payee completement
// $sql.= " OR f.close_code IS NOT NULL)"; // Classee payee partiellement
$sql.= " AND ff.type IS NULL"; // Renvoi vrai si pas facture de remplacement
$sql.= " AND f.type != 2"; // Type non 2 si facture non avoir
$sql.= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir
if ($socid > 0) $sql.=" AND f.fk_soc = ".$socid;
$sql.= " ORDER BY f.facnumber";