NEW Add mass action "validate" on supplier invoices.

NEW Add date_valid and date_pointoftax on supplier invoices.
This commit is contained in:
Laurent Destailleur 2017-07-14 14:40:09 +02:00
parent bbc8994d36
commit 3ac85e10c5
9 changed files with 128 additions and 14 deletions

View File

@ -2044,7 +2044,12 @@ class Facture extends CommonInvoice
dol_syslog(get_class($this)."::validate no draft status", LOG_WARNING);
return 0;
}
if (count($this->lines) <= 0)
{
$langs->load("errors");
$this->error=$langs->trans("ErrorObjectMustHaveLinesToBeValidated", $this->ref);
return -1;
}
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->creer))
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->facture->invoice_advance->validate)))
{

View File

@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
/* Copyright (C) 2015-2017 Laurent Destailleur <eldy@users.sourceforge.net>
*
* 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
@ -26,6 +26,7 @@
// $objectclass and $$objectlabel must be defined
// $parameters, $object, $action must be defined for the hook.
// $permtoread, $permtocreate and $permtodelete may be defined
// $uploaddir may be defined (example to $conf->projet->dir_output."/";)
// $toselect may be defined
@ -524,6 +525,66 @@ if ($action == 'remove_file')
$action='';
}
// Validate records
if (! $error && $massaction == 'validate' && $permtocreate)
{
if ($object->element == 'invoice_supplier' && ! empty($conf->stock->enabled) && ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL))
{
$langs->load("errors");
setEventMessages($langs->trans('ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null, 'errors');
$error++;
}
if (! $error)
{
$db->begin();
$objecttmp=new $objectclass($db);
$nbok = 0;
foreach($toselect as $toselectid)
{
$result=$objecttmp->fetch($toselectid);
if ($result > 0)
{
//if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
//else
$result = $objecttmp->validate($user);
if ($result == 0)
{
$langs->load("errors");
setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null, 'errors');
$error++;
break;
}
elseif ($result < 0)
{
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
else $nbok++;
}
else
{
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
}
if (! $error)
{
if ($nbok > 1) setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
else setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
$db->commit();
}
else
{
$db->rollback();
}
//var_dump($listofobjectthirdparties);exit;
}
}
// Delete records
if (! $error && $massaction == 'delete' && $permtodelete)
{

View File

@ -31,7 +31,7 @@
*/
if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr');
if (! defined('DOL_VERSION')) define('DOL_VERSION','6.0.0-beta'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c
if (! defined('DOL_VERSION')) define('DOL_VERSION','7.0.0-beta'); // a.b.c-alpha, a.b.c-beta, a.b.c-rcX or a.b.c
if (! defined('EURO')) define('EURO',chr(128));

View File

@ -130,7 +130,7 @@ class FactureFournisseur extends CommonInvoice
public $multicurrency_total_ttc;
//! id of source invoice if replacement invoice or credit note
public $fk_facture_source;
/**
* Standard invoice
*/
@ -883,7 +883,7 @@ class FactureFournisseur extends CommonInvoice
}
// Fin appel triggers
}
if (! $error)
{
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det WHERE fk_facture_fourn = '.$rowid.';';
@ -902,7 +902,7 @@ class FactureFournisseur extends CommonInvoice
$error++;
}
}
if (! $error)
{
// Delete linked object
@ -1081,20 +1081,29 @@ class FactureFournisseur extends CommonInvoice
public function validate($user, $force_number='', $idwarehouse=0, $notrigger=0)
{
global $conf,$langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$now=dol_now();
$error=0;
dol_syslog(get_class($this).'::validate user='.$user->id.', force_number='.$force_number.', idwarehouse='.$idwarehouse);
// Protection
// Check parameters
if ($this->statut > self::STATUS_DRAFT) // This is to avoid to validate twice (avoid errors on logs and stock management)
{
dol_syslog(get_class($this)."::validate no draft status", LOG_WARNING);
return 0;
}
// Check parameters
if (preg_match('/^'.preg_quote($langs->trans("CopyOf").' ').'/', $this->ref_supplier))
{
$this->error=$langs->trans("ErrorFieldFormat",$langs->transnoentities("RefSupplier")).'. '.$langs->trans('RemoveString',$langs->transnoentitiesnoconv("CopyOf"));
$langs->load("errors");
$this->error=$langs->trans("ErrorFieldFormat",$langs->transnoentities("RefSupplier")).'. '.$langs->trans('RemoveString',$langs->transnoentitiesnoconv("CopyOf"));
return -1;
}
if (count($this->lines) <= 0)
{
$langs->load("errors");
$this->error=$langs->trans("ErrorObjectMustHaveLinesToBeValidated", $this->ref);
return -1;
}
@ -1116,7 +1125,7 @@ class FactureFournisseur extends CommonInvoice
$this->newref = $num;
$sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn";
$sql.= " SET ref='".$num."', fk_statut = 1, fk_user_valid = ".$user->id;
$sql.= " SET ref='".$num."', fk_statut = 1, fk_user_valid = ".$user->id.", date_valid = '".$this->db->idate($now)."'";
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::validate", LOG_DEBUG);

View File

@ -194,7 +194,7 @@ if (empty($reshook))
{
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha') || GETPOST('button_removefilter.x','alpha')) // All test must be present to be compatible with all browsers
if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter','alpha') || GETPOST('button_removefilter.x','alpha')) // All tests must be present to be compatible with all browsers
{
$search_all="";
$search_user='';
@ -237,6 +237,7 @@ if (empty($reshook))
$objectclass='FactureFournisseur';
$objectlabel='SupplierInvoices';
$permtoread = $user->rights->fournisseur->facture->lire;
$permtocreate = $user->rights->fournisseur->facture->creer;
$permtodelete = $user->rights->fournisseur->facture->supprimer;
$uploaddir = $conf->fournisseur->facture->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
@ -463,7 +464,8 @@ if ($resql)
// List of mass actions available
$arrayofmassactions = array(
//'presend'=>$langs->trans("SendByMail"),
'validate'=>$langs->trans("Validate"),
//'presend'=>$langs->trans("SendByMail"),
//'builddoc'=>$langs->trans("PDFMerge"),
);
//if($user->rights->fournisseur->facture->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");

View File

@ -412,7 +412,8 @@ else
array('from'=>'3.8.0', 'to'=>'3.9.0'),
array('from'=>'3.9.0', 'to'=>'4.0.0'),
array('from'=>'4.0.0', 'to'=>'5.0.0'),
array('from'=>'5.0.0', 'to'=>'6.0.0')
array('from'=>'5.0.0', 'to'=>'6.0.0'),
array('from'=>'6.0.0', 'to'=>'7.0.0')
);
$count=0;

View File

@ -0,0 +1,31 @@
--
-- Be carefull to requests order.
-- This file must be loaded by calling /install/index.php page
-- when current version is 6.0.0 or higher.
--
-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new;
-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;
-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60);
-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname;
-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60);
-- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name;
-- To drop an index: -- VMYSQL4.0 DROP INDEX nomindex on llx_table
-- To drop an index: -- VPGSQL8.0 DROP INDEX nomindex
-- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y
-- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y
-- To make pk to be auto increment (mysql): -- VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT;
-- To make pk to be auto increment (postgres): -- VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE
-- To set a field as NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NULL;
-- To set a field as NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL;
-- To set a field as NOT NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NOT NULL;
-- To set a field as NOT NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET NOT NULL;
-- To set a field as default NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL;
-- Note: fields with type BLOB/TEXT can't have default value.
-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user);
-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup);
ALTER TABLE llx_facture_fourn ADD COLUMN date_pointoftax date DEFAULT NULL;
ALTER TABLE llx_facture_fourn ADD COLUMN date_valid date;

View File

@ -33,6 +33,8 @@ create table llx_facture_fourn
datec datetime, -- date de creation de la facture
datef date, -- date de la facture
date_pointoftax date DEFAULT NULL, -- date point of tax (for GB)
date_valid date, -- date validation
tms timestamp, -- date creation/modification
libelle varchar(255),
paye smallint DEFAULT 0 NOT NULL,

View File

@ -194,6 +194,9 @@ ErrorDuplicateTrigger=Error, duplicate trigger name %s. Already loaded from %s.
ErrorNoWarehouseDefined=Error, no warehouses defined.
ErrorBadLinkSourceSetButBadValueForRef=The link you use is not valid. A 'source' for payment is defined, but value for 'ref' is not valid.
ErrorTooManyErrorsProcessStopped=Too many errors. Process was stopped.
ErrorMassValidationNotAllowedWhenStockIncreaseOnAction=Mass validation is not possible when option to increase/decrease stock is set on this action (you must validate one by one so you can define the warehouse to increase/decrease)
ErrorObjectMustHaveStatusDraftToBeValidated=Object %s must have status 'Draft' to be validated.
ErrorObjectMustHaveLinesToBeValidated=Object %s must have lines to be validated.
# Warnings
WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user.