Merge pull request #787 from grandoc/develop

add numbering for supplier invoice
This commit is contained in:
Laurent Destailleur 2013-03-30 05:23:45 -07:00
commit 7caa715fea
4 changed files with 53 additions and 21 deletions

View File

@ -5,6 +5,7 @@
* Copyright (C) 2005 Marc Barilley <marc@ocebo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
*
* 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
@ -40,7 +41,7 @@ class FactureFournisseur extends CommonInvoice
public $fk_element='fk_facture_fourn';
protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
var $ref; // TODO deprecated
var $ref;
var $product_ref;
var $ref_supplier;
var $socid;
@ -132,7 +133,8 @@ class FactureFournisseur extends CommonInvoice
$totalht = ($amount - $remise);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facture_fourn (";
$sql.= "facnumber";
$sql.= "ref";
$sql.= ", facnumber";
$sql.= ", entity";
$sql.= ", libelle";
$sql.= ", fk_soc";
@ -144,7 +146,8 @@ class FactureFournisseur extends CommonInvoice
$sql.= ", date_lim_reglement";
$sql.= ")";
$sql.= " VALUES (";
$sql.= "'".$this->db->escape($number)."'";
$sql.= "'(PROV)'";
$sql.= ", '".$this->db->escape($number)."'";
$sql.= ", ".$conf->entity;
$sql.= ", '".$this->db->escape($this->libelle)."'";
$sql.= ", ".$this->socid;
@ -259,6 +262,7 @@ class FactureFournisseur extends CommonInvoice
$sql = "SELECT";
$sql.= " t.rowid,";
$sql.= " t.ref,";
$sql.= " t.facnumber,";
$sql.= " t.entity,";
$sql.= " t.type,";
@ -294,7 +298,7 @@ class FactureFournisseur extends CommonInvoice
$sql.= ' s.nom as socnom, s.rowid as socid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as t,'.MAIN_DB_PREFIX.'societe as s';
if ($id) $sql.= " WHERE t.rowid=".$id;
if ($ref) $sql.= " WHERE t.rowid='".$this->db->escape($ref)."'"; // ref is id (facnumber is supplier ref)
if ($ref) $sql.= " WHERE t.ref='".$this->db->escape($ref)."'"; // ref is id (facnumber is supplier ref)
$sql.= ' AND t.fk_soc = s.rowid';
dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG);
@ -306,7 +310,7 @@ class FactureFournisseur extends CommonInvoice
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
$this->ref = $obj->ref;
$this->ref_supplier = $obj->facnumber;
$this->facnumber = $obj->facnumber;
@ -459,6 +463,7 @@ class FactureFournisseur extends CommonInvoice
$error=0;
// Clean parameters
if (isset($this->ref)) $this->ref=trim($this->ref);
if (isset($this->ref_supplier)) $this->ref_supplier=trim($this->ref_supplier);
if (isset($this->entity)) $this->entity=trim($this->entity);
if (isset($this->type)) $this->type=trim($this->type);
@ -495,6 +500,7 @@ class FactureFournisseur extends CommonInvoice
// Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
$sql.= " facnumber=".(isset($this->facnumber)?"'".$this->db->escape($this->facnumber)."'":"null").",";
$sql.= " entity=".(isset($this->entity)?$this->entity:"null").",";
$sql.= " type=".(isset($this->type)?$this->type:"null").",";
@ -834,7 +840,7 @@ class FactureFournisseur extends CommonInvoice
}
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " SET fk_statut = 1, fk_user_valid = ".$user->id;
$sql.= " SET ref='".$num."', fk_statut = 1, fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::validate sql=".$sql);
@ -1181,17 +1187,17 @@ class FactureFournisseur extends CommonInvoice
dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG);
$error=0;
$this->db->begin();
$this->db->begin();
if (! $error && ! $notrigger)
{
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('LINEBILL_SUPPLIER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Appel des triggers
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db);
$result=$interface->run_triggers('LINEBILL_SUPPLIER_DELETE',$this,$user,$langs,$conf);
if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// Fin appel triggers
}
@ -1213,7 +1219,7 @@ class FactureFournisseur extends CommonInvoice
if (! $error)
{
// Mise a jour prix facture
$this->update_price();
$this->update_price();
}
if (! $error)

View File

@ -5,6 +5,7 @@
* Copyright (C) 2005 Marc Barilley <marc@ocebo.fr>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
*
* 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
@ -49,6 +50,7 @@ $errors=array();
$id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int'));
$action = GETPOST("action");
$confirm = GETPOST("confirm");
$ref = GETPOST('ref','alpha');
//PDF
$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
@ -65,6 +67,12 @@ $hookmanager->initHooks(array('invoicesuppliercard'));
$object=new FactureFournisseur($db);
// Load object
if ($id > 0 || ! empty($ref))
{
$ret=$object->fetch($id, $ref);
}
/*
@ -258,7 +266,8 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
$db->begin();
// Creation facture
$object->ref = $_POST['facnumber'];
$object->ref = $_POST['ref'];
$object->facnumber = $_POST['facnumber'];
$object->socid = $_POST['socid'];
$object->libelle = $_POST['libelle'];
$object->date = $datefacture;
@ -1281,6 +1290,22 @@ else
// Confirmation de la validation
if ($action == 'valid')
{
// on verifie si l'objet est en numerotation provisoire
$objectref = substr($object->ref, 1, 4);
if ($objectref == 'PROV')
{
$savdate=$object->date;
if (! empty($conf->global->FAC_FORCE_DATE_VALIDATION))
{
$object->date=dol_now();
$object->date_lim_reglement=$object->calculate_date_lim_reglement();
}
$numref = $object->getNextNumRef($soc);
}
else
{
$numref = $object->ref;
}
$formquestion=array();
if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1))
{
@ -1322,7 +1347,7 @@ else
// Ref
print '<tr><td nowrap="nowrap" width="20%">'.$langs->trans("Ref").'</td><td colspan="4">';
print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref');
print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
print '</td>';
print "</tr>\n";

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
*
* 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
@ -102,7 +103,7 @@ $htmlother=new FormOther($db);
llxHeader('',$langs->trans("SuppliersInvoices"),'EN:Suppliers_Invoices|FR:FactureFournisseur|ES:Facturas_de_proveedores');
$sql = "SELECT s.rowid as socid, s.nom, ";
$sql.= " fac.rowid as ref, fac.rowid as facid, fac.facnumber, fac.datef, fac.date_lim_reglement as date_echeance,";
$sql.= " fac.rowid as facid, fac.ref, fac.facnumber, fac.datef, fac.date_lim_reglement as date_echeance,";
$sql.= " fac.total_ht, fac.total_ttc, fac.paye as paye, fac.fk_statut as fk_statut, fac.libelle";
if (!$user->rights->societe->client->voir && !$socid) $sql .= ", sc.fk_soc, sc.fk_user ";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as fac";

View File

@ -48,6 +48,9 @@ alter table llx_contratdet add column buy_price_ht double(24,8) DEFAULT 0 after
-- serialised array, to store value of select list choices for example
alter table llx_extrafields add column param text after pos;
-- numbering on supplier invoice
alter table llx_facture_fourn add column ref varchar(30) NOT NULL after rowid;
alter table llx_propal CHANGE COLUMN fk_adresse_livraison fk_delivery_address integer;
alter table llx_commande CHANGE COLUMN fk_adresse_livraison fk_delivery_address integer;
@ -205,6 +208,3 @@ ALTER TABLE llx_user ADD COLUMN town varchar(50);
ALTER TABLE llx_user ADD COLUMN fk_state integer DEFAULT 0;
ALTER TABLE llx_user ADD COLUMN fk_country integer DEFAULT 0;