Update cactus numbering model

This commit is contained in:
aspangaro 2016-11-11 07:36:26 +01:00
parent 60219fa84d
commit c65678d00a
2 changed files with 81 additions and 29 deletions

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2005-2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com> * Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2016 Alexandre Spangaro <aspangaro@zendsi.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,14 +22,15 @@
/** /**
* \file htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_cactus.php * \file htdocs/core/modules/supplier_invoice/mod_facture_fournisseur_cactus.php
* \ingroup supplier invoice * \ingroup supplier invoice
* \brief File containing the Cactus Class of numbering models of suppliers invoices references * \brief File containing class for the numbering module Cactus
*/ */
require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_invoice/modules_facturefournisseur.php'; require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_invoice/modules_facturefournisseur.php';
/** /**
* Cactus Class of numbering models of suppliers invoices references * \class mod_facture_fournisseur_cactus
* \brief Cactus Class of numbering models of suppliers invoices references
*/ */
class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
{ {
@ -36,6 +38,8 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
var $error = ''; var $error = '';
var $nom = 'Cactus'; var $nom = 'Cactus';
var $prefixinvoice='SI'; var $prefixinvoice='SI';
var $prefixcreditnote='SA';
var $prefixdeposit='SD';
/** /**
@ -46,7 +50,8 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
function info() function info()
{ {
global $langs; global $langs;
return $langs->trans("SimpleNumRefModelDesc",$this->prefixinvoice); $langs->load("bills");
return $langs->trans("CactusNumRefModelDesc1",$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit);
} }
@ -61,45 +66,90 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
} }
/** /**
* Tests if the numbers already in force in the database do not cause conflicts that would prevent this numbering. * Tests if the numbers already in force in the database do not cause conflicts that would prevent this numbering.
* *
* @return boolean false if conflict, true if ok * @return boolean false if conflict, true if ok
*/ */
function canBeActivated() function canBeActivated()
{ {
global $conf,$langs,$db; global $conf,$langs,$db;
$siyymm=''; $max=''; $langs->load("bills");
// Check invoice num
$siyymm=''; $max='';
$posindice=8; $posindice=8;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max";
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn"; $sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " WHERE ref LIKE '".$this->prefixinvoice."____-%'"; $sql.= " WHERE ref LIKE '".$this->prefixinvoice."____-%'";
$sql.= " AND entity = ".$conf->entity; $sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql); $resql=$db->query($sql);
if ($resql) if ($resql)
{ {
$row = $db->fetch_row($resql); $row = $db->fetch_row($resql);
if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; } if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; }
} }
if (! $siyymm || preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$siyymm)) if (! $siyymm || preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$siyymm))
{ {
return true; return true;
} }
else else
{ {
$langs->load("errors"); $langs->load("errors");
$this->error=$langs->trans('ErrorNumRefModel',$max); $this->error=$langs->trans('ErrorNumRefModel',$max);
return false; return false;
} }
// Check credit note num
$siyymm='';
$posindice=8;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " WHERE ref LIKE '".$this->prefixcreditnote."____-%'";
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; }
}
if ($siyymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$siyymm))
{
$this->error=$langs->trans('ErrorNumRefModel',$max);
return false;
}
// Check deposit num
$siyymm='';
$posindice=8;
$sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL
$sql.= " FROM ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " WHERE ref LIKE '".$this->prefixdeposit."____-%'";
$sql.= " AND entity = ".$conf->entity;
$resql=$db->query($sql);
if ($resql)
{
$row = $db->fetch_row($resql);
if ($row) { $siyymm = substr($row[0],0,6); $max=$row[0]; }
}
if ($siyymm && ! preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i',$siyymm))
{
$this->error=$langs->trans('ErrorNumRefModel',$max);
return false;
}
} }
/** /**
* Return next value * Return next value
* *
* @param Societe $objsoc Object third party * @param Societe $objsoc Object third party
* @param Object $object Object * @param Object $object Object invoice
* @param string $mode 'next' for next value or 'last' for last value * @param string $mode 'next' for next value or 'last' for last value
* @return string Value if OK, 0 if KO * @return string Value if OK, 0 if KO
*/ */
@ -108,6 +158,7 @@ class mod_facture_fournisseur_cactus extends ModeleNumRefSuppliersInvoices
global $db,$conf; global $db,$conf;
if ($object->type == 2) $prefix=$this->prefixcreditnote; if ($object->type == 2) $prefix=$this->prefixcreditnote;
else if ($facture->type == 3) $prefix=$this->prefixdeposit;
else $prefix=$this->prefixinvoice; else $prefix=$this->prefixinvoice;
// D'abord on recupere la valeur max // D'abord on recupere la valeur max

View File

@ -446,6 +446,7 @@ PDFCrevetteDescription=Invoice PDF template Crevette. A complete invoice templat
TerreNumRefModelDesc1=Return number with format %syymm-nnnn for standard invoices and %syymm-nnnn for credit notes where yy is year, mm is month and nnnn is a sequence with no break and no return to 0 TerreNumRefModelDesc1=Return number with format %syymm-nnnn for standard invoices and %syymm-nnnn for credit notes where yy is year, mm is month and nnnn is a sequence with no break and no return to 0
MarsNumRefModelDesc1=Return number with format %syymm-nnnn for standard invoices, %syymm-nnnn for replacement invoices, %syymm-nnnn for deposit invoices and %syymm-nnnn for credit notes where yy is year, mm is month and nnnn is a sequence with no break and no return to 0 MarsNumRefModelDesc1=Return number with format %syymm-nnnn for standard invoices, %syymm-nnnn for replacement invoices, %syymm-nnnn for deposit invoices and %syymm-nnnn for credit notes where yy is year, mm is month and nnnn is a sequence with no break and no return to 0
TerreNumRefModelError=A bill starting with $syymm already exists and is not compatible with this model of sequence. Remove it or rename it to activate this module. TerreNumRefModelError=A bill starting with $syymm already exists and is not compatible with this model of sequence. Remove it or rename it to activate this module.
CactusNumRefModelDesc1=Return number with format %syymm-nnnn for standard invoices, %syymm-nnnn for credit notes and %syymm-nnnn for deposit invoices where yy is year, mm is month and nnnn is a sequence with no break and no return to 0
##### Types de contacts ##### ##### Types de contacts #####
TypeContact_facture_internal_SALESREPFOLL=Representative following-up customer invoice TypeContact_facture_internal_SALESREPFOLL=Representative following-up customer invoice
TypeContact_facture_external_BILLING=Customer invoice contact TypeContact_facture_external_BILLING=Customer invoice contact