Fix multicompany: recurring invoice must be in same env than template.
This commit is contained in:
parent
c28a62e051
commit
d821df070b
@ -241,7 +241,7 @@ class FactureRec extends CommonInvoice
|
|||||||
*/
|
*/
|
||||||
function fetch($rowid, $ref='', $ref_ext='', $ref_int='')
|
function fetch($rowid, $ref='', $ref_ext='', $ref_int='')
|
||||||
{
|
{
|
||||||
$sql = 'SELECT f.rowid, f.titre, f.fk_soc, f.amount, f.tva, f.total, f.total_ttc, f.remise_percent, f.remise_absolue, f.remise';
|
$sql = 'SELECT f.rowid, f.entity, f.titre, f.fk_soc, f.amount, f.tva, f.total, f.total_ttc, f.remise_percent, f.remise_absolue, f.remise';
|
||||||
$sql.= ', f.date_lim_reglement as dlr';
|
$sql.= ', f.date_lim_reglement as dlr';
|
||||||
$sql.= ', f.note_private, f.note_public, f.fk_user_author';
|
$sql.= ', f.note_private, f.note_public, f.fk_user_author';
|
||||||
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet';
|
$sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet';
|
||||||
@ -269,6 +269,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$obj = $this->db->fetch_object($result);
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
$this->id = $obj->rowid;
|
$this->id = $obj->rowid;
|
||||||
|
$this->entity = $obj->entity;
|
||||||
$this->titre = $obj->titre;
|
$this->titre = $obj->titre;
|
||||||
$this->ref = $obj->titre;
|
$this->ref = $obj->titre;
|
||||||
$this->ref_client = $obj->ref_client;
|
$this->ref_client = $obj->ref_client;
|
||||||
@ -754,7 +755,7 @@ class FactureRec extends CommonInvoice
|
|||||||
if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
|
if ($num) $this->output.=$langs->trans("FoundXQualifiedRecurringInvoiceTemplate", $num)."\n";
|
||||||
else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
|
else $this->output.=$langs->trans("NoQualifiedRecurringInvoiceTemplateFound");
|
||||||
|
|
||||||
while ($i < $num)
|
while ($i < $num) // Loop on each template invoice
|
||||||
{
|
{
|
||||||
$line = $db->fetch_object($resql);
|
$line = $db->fetch_object($resql);
|
||||||
|
|
||||||
@ -774,7 +775,7 @@ class FactureRec extends CommonInvoice
|
|||||||
$facture->date = $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
|
$facture->date = $facturerec->date_when; // We could also use dol_now here but we prefer date_when so invoice has real date when we would like even if we generate later.
|
||||||
$facture->socid = $facturerec->socid;
|
$facture->socid = $facturerec->socid;
|
||||||
|
|
||||||
$invoiceidgenerated = $facture->create($user); // This will also update fields of recurring invoice
|
$invoiceidgenerated = $facture->create($user);
|
||||||
if ($invoiceidgenerated <= 0)
|
if ($invoiceidgenerated <= 0)
|
||||||
{
|
{
|
||||||
$this->errors = $facture->errors;
|
$this->errors = $facture->errors;
|
||||||
@ -794,14 +795,14 @@ class FactureRec extends CommonInvoice
|
|||||||
|
|
||||||
if (! $error && $invoiceidgenerated >= 0)
|
if (! $error && $invoiceidgenerated >= 0)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$db->commit("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
|
||||||
dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
|
dol_syslog("createRecurringInvoices Process invoice template ".$facturerec->ref." is finished with a success generation");
|
||||||
$nb_create++;
|
$nb_create++;
|
||||||
$this->output.=$langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
|
$this->output.=$langs->trans("InvoiceGeneratedFromTemplate", $facture->ref, $facturerec->ref)."\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$db->rollback();
|
$db->rollback("createRecurringInvoices Process invoice template id=".$facturerec->id.", ref=".$facturerec->ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
$i++;
|
$i++;
|
||||||
|
|||||||
@ -239,6 +239,7 @@ class Facture extends CommonInvoice
|
|||||||
if (! $this->cond_reglement_id) $this->cond_reglement_id = 0;
|
if (! $this->cond_reglement_id) $this->cond_reglement_id = 0;
|
||||||
if (! $this->mode_reglement_id) $this->mode_reglement_id = 0;
|
if (! $this->mode_reglement_id) $this->mode_reglement_id = 0;
|
||||||
$this->brouillon = 1;
|
$this->brouillon = 1;
|
||||||
|
if (empty($this->entity)) $this->entity = $conf->entity;
|
||||||
|
|
||||||
// Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate)
|
// Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate)
|
||||||
if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
|
if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code);
|
||||||
@ -279,7 +280,8 @@ class Facture extends CommonInvoice
|
|||||||
$_facrec = new FactureRec($this->db);
|
$_facrec = new FactureRec($this->db);
|
||||||
$result=$_facrec->fetch($this->fac_rec);
|
$result=$_facrec->fetch($this->fac_rec);
|
||||||
|
|
||||||
$this->socid = $_facrec->socid;
|
$this->socid = $_facrec->socid; // Invoice created on same thirdparty than template
|
||||||
|
$this->entity = $_facrec->entity; // Invoice created in same entity than template
|
||||||
|
|
||||||
// Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI
|
// Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI
|
||||||
$this->fk_project = GETPOST('projectid','int') > 0 ? GETPOST('projectid','int') : $_facrec->fk_project;
|
$this->fk_project = GETPOST('projectid','int') > 0 ? GETPOST('projectid','int') : $_facrec->fk_project;
|
||||||
@ -350,7 +352,7 @@ class Facture extends CommonInvoice
|
|||||||
$sql.= ")";
|
$sql.= ")";
|
||||||
$sql.= " VALUES (";
|
$sql.= " VALUES (";
|
||||||
$sql.= "'(PROV)'";
|
$sql.= "'(PROV)'";
|
||||||
$sql.= ", ".$conf->entity;
|
$sql.= ", ".$this->entity;
|
||||||
$sql.= ", ".($this->ref_ext?"'".$this->db->escape($this->ref_ext)."'":"null");
|
$sql.= ", ".($this->ref_ext?"'".$this->db->escape($this->ref_ext)."'":"null");
|
||||||
$sql.= ", '".$this->db->escape($this->type)."'";
|
$sql.= ", '".$this->db->escape($this->type)."'";
|
||||||
$sql.= ", '".$socid."'";
|
$sql.= ", '".$socid."'";
|
||||||
|
|||||||
@ -368,6 +368,7 @@ class Cronjob extends CommonObject
|
|||||||
|
|
||||||
$sql = "SELECT";
|
$sql = "SELECT";
|
||||||
$sql.= " t.rowid,";
|
$sql.= " t.rowid,";
|
||||||
|
$sql.= " t.entity,";
|
||||||
$sql.= " t.tms,";
|
$sql.= " t.tms,";
|
||||||
$sql.= " t.datec,";
|
$sql.= " t.datec,";
|
||||||
$sql.= " t.jobtype,";
|
$sql.= " t.jobtype,";
|
||||||
@ -442,6 +443,7 @@ class Cronjob extends CommonObject
|
|||||||
$line->id = $obj->rowid;
|
$line->id = $obj->rowid;
|
||||||
$line->ref = $obj->rowid;
|
$line->ref = $obj->rowid;
|
||||||
|
|
||||||
|
$line->entity = $obj->entity;
|
||||||
$line->tms = $this->db->jdate($obj->tms);
|
$line->tms = $this->db->jdate($obj->tms);
|
||||||
$line->datec = $this->db->jdate($obj->datec);
|
$line->datec = $this->db->jdate($obj->datec);
|
||||||
$line->label = $obj->label;
|
$line->label = $obj->label;
|
||||||
@ -896,6 +898,7 @@ class Cronjob extends CommonObject
|
|||||||
|
|
||||||
// Update last run date start (to track running jobs)
|
// Update last run date start (to track running jobs)
|
||||||
$this->datelastrun=$now;
|
$this->datelastrun=$now;
|
||||||
|
$this->datelastresult=null;
|
||||||
$this->lastoutput='';
|
$this->lastoutput='';
|
||||||
$this->lastresult='';
|
$this->lastresult='';
|
||||||
$this->nbrun=$this->nbrun + 1;
|
$this->nbrun=$this->nbrun + 1;
|
||||||
@ -1096,6 +1099,8 @@ class Cronjob extends CommonObject
|
|||||||
dol_syslog(get_class($this)."::run_jobs output_arr:".var_export($output_arr,true)." lastoutput=".$this->lastoutput." lastresult=".$this->lastresult, LOG_DEBUG);
|
dol_syslog(get_class($this)."::run_jobs output_arr:".var_export($output_arr,true)." lastoutput=".$this->lastoutput." lastresult=".$this->lastresult, LOG_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::run_jobs now we update job to track it is finished (with success or error)");
|
||||||
|
|
||||||
$this->datelastresult=dol_now();
|
$this->datelastresult=dol_now();
|
||||||
$result = $this->update($user); // This include begin/commit
|
$result = $this->update($user); // This include begin/commit
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
|
|||||||
@ -109,8 +109,8 @@ else
|
|||||||
{
|
{
|
||||||
if (empty($user->id))
|
if (empty($user->id))
|
||||||
{
|
{
|
||||||
echo "User user login: ".$userlogin." does not exists";
|
echo "User login: ".$userlogin." does not exists";
|
||||||
dol_syslog("User user login:".$userlogin." does not exists", LOG_ERR);
|
dol_syslog("User login:".$userlogin." does not exists", LOG_ERR);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,22 +152,22 @@ if(is_array($object->lines) && (count($object->lines)>0))
|
|||||||
//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
|
//If date_next_jobs is less of current date, execute the program, and store the execution time of the next execution in database
|
||||||
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
|
if (($line->datenextrun < $now) && (empty($line->datestart) || $line->datestart <= $now) && (empty($line->dateend) || $line->dateend >= $now))
|
||||||
{
|
{
|
||||||
dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun,'dayhourtext')." line->dateend:".dol_print_date($line->dateend,'dayhourtext')." now:".dol_print_date($now,'dayhourtext'));
|
dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun,'dayhourrfc')." line->dateend:".dol_print_date($line->dateend,'dayhourrfc')." now:".dol_print_date($now,'dayhourrfc'));
|
||||||
|
|
||||||
$cronjob=new Cronjob($db);
|
$cronjob=new Cronjob($db);
|
||||||
$result=$cronjob->fetch($line->id);
|
$result=$cronjob->fetch($line->id);
|
||||||
if ($result<0)
|
if ($result<0)
|
||||||
{
|
{
|
||||||
echo "Error:".$cronjob->error;
|
echo "Error cronjob->fetch: ".$cronjob->error;
|
||||||
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
|
dol_syslog("cron_run_jobs.php::fetch Error ".$cronjob->error, LOG_ERR);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
// Execute job
|
// Execute job
|
||||||
$result=$cronjob->run_jobs($userlogin);
|
$result=$cronjob->run_jobs($userlogin);
|
||||||
if ($result<0)
|
if ($result<0)
|
||||||
{
|
{
|
||||||
echo "Error:".$cronjob->error;
|
echo "Error cronjob->run_job: ".$cronjob->error;
|
||||||
dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
|
dol_syslog("cron_run_jobs.php::run_jobs Error ".$cronjob->error, LOG_ERR);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +175,8 @@ if(is_array($object->lines) && (count($object->lines)>0))
|
|||||||
$result=$cronjob->reprogram_jobs($userlogin, $now);
|
$result=$cronjob->reprogram_jobs($userlogin, $now);
|
||||||
if ($result<0)
|
if ($result<0)
|
||||||
{
|
{
|
||||||
echo "Error:".$cronjob->error;
|
echo "Error cronjob->reprogram_job: ".$cronjob->error;
|
||||||
dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
|
dol_syslog("cron_run_jobs.php::reprogram_jobs Error ".$cronjob->error, LOG_ERR);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user