From 2810315dc526dbbc5db2b307eaf4e6cd3adf709f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 18 Sep 2021 13:19:29 +0200 Subject: [PATCH] Fix payment of registration of event --- .../class/conferenceorboothattendee.class.php | 2 + .../install/mysql/migration/13.0.0-14.0.0.sql | 2 + .../eventorganization/attendee_register.php | 51 +++++++++++-------- htdocs/public/payment/newpayment.php | 20 +++++++- 4 files changed, 51 insertions(+), 24 deletions(-) diff --git a/htdocs/eventorganization/class/conferenceorboothattendee.class.php b/htdocs/eventorganization/class/conferenceorboothattendee.class.php index 7fb77b69b64..572d6f13856 100644 --- a/htdocs/eventorganization/class/conferenceorboothattendee.class.php +++ b/htdocs/eventorganization/class/conferenceorboothattendee.class.php @@ -108,6 +108,7 @@ class ConferenceOrBoothAttendee extends CommonObject 'email' => array('type'=>'mail', 'label'=>'EmailAttendee', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>1, 'index'=>1,), 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php:1:status = 1 AND entity IN (__SHARED_ENTITIES__)', 'label'=>'ThirdParty', 'enabled'=>'1', 'position'=>40, 'notnull'=>-1, 'visible'=>1, 'index'=>1, 'help'=>"LinkToThirparty", 'picto'=>'company', 'css'=>'tdoverflowmax150 maxwidth500'), 'date_subscription' => array('type'=>'datetime', 'label'=>'DateOfRegistration', 'enabled'=>'1', 'position'=>56, 'notnull'=>0, 'visible'=>1, 'showoncombobox'=>'1',), + 'fk_invoice' => array('type'=>'integer:Facture:compta/facture/class/facture.class.php', 'label'=>'Invoice', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>-1, 'index'=>0, 'picto'=>'bill', 'css'=>'tdoverflowmax150 maxwidth500'), 'amount' => array('type'=>'price', 'label'=>'AmountPaid', 'enabled'=>'1', 'position'=>57, 'notnull'=>0, 'visible'=>1, 'default'=>'null', 'isameasure'=>'1', 'help'=>"AmountOfSubscriptionPaid",), 'note_public' => array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>'1', 'position'=>61, 'notnull'=>0, 'visible'=>3,), 'note_private' => array('type'=>'html', 'label'=>'NotePrivate', 'enabled'=>'1', 'position'=>62, 'notnull'=>0, 'visible'=>3,), @@ -126,6 +127,7 @@ class ConferenceOrBoothAttendee extends CommonObject public $fk_actioncomm; public $email; public $date_subscription; + public $fk_invoice; public $amount; public $note_public; public $note_private; diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 11358781e37..63f20198658 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -403,6 +403,7 @@ CREATE TABLE llx_eventorganization_conferenceorboothattendee( fk_soc integer, fk_actioncomm integer, fk_project integer NOT NULL, + fk_invoice integer NULL, email varchar(100), date_subscription datetime, amount double DEFAULT NULL, @@ -422,6 +423,7 @@ CREATE TABLE llx_eventorganization_conferenceorboothattendee( -- VPGSQL8.2 ALTER TABLE llx_eventorganization_conferenceorboothattendee ALTER COLUMN fk_actioncomm DROP NOT NULL; ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD COLUMN fk_project integer NOT NULL; +ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD COLUMN fk_invoice integer NULL; ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD INDEX idx_eventorganization_conferenceorboothattendee_rowid (rowid); ALTER TABLE llx_eventorganization_conferenceorboothattendee ADD INDEX idx_eventorganization_conferenceorboothattendee_ref (ref); diff --git a/htdocs/public/eventorganization/attendee_register.php b/htdocs/public/eventorganization/attendee_register.php index 6e169749453..db3acde4628 100644 --- a/htdocs/public/eventorganization/attendee_register.php +++ b/htdocs/public/eventorganization/attendee_register.php @@ -470,34 +470,41 @@ if (empty($reshook) && $action == 'add' && (!empty($conference->id) && $conferen $errmsg .= $productforinvoicerow->error; } else { $facture = new Facture($db); - $facture->type = Facture::TYPE_STANDARD; - $facture->socid = $thirdparty->id; - $facture->paye = 0; - $facture->date = dol_now(); - $facture->cond_reglement_id = $confattendee->cond_reglement_id; - $facture->fk_project = $project->id; + if (empty($confattendee->fk_invoice)) { + $facture->type = Facture::TYPE_STANDARD; + $facture->socid = $thirdparty->id; + $facture->paye = 0; + $facture->date = dol_now(); + $facture->cond_reglement_id = $confattendee->cond_reglement_id; + $facture->fk_project = $project->id; + $facture->status = Facture::STATUS_DRAFT; - if (empty($facture->cond_reglement_id)) { - $paymenttermstatic = new PaymentTerm($confattendee->db); - $facture->cond_reglement_id = $paymenttermstatic->getDefaultId(); if (empty($facture->cond_reglement_id)) { - $error++; - $confattendee->error = 'ErrorNoPaymentTermRECEPFound'; - $confattendee->errors[] = $confattendee->error; + $paymenttermstatic = new PaymentTerm($confattendee->db); + $facture->cond_reglement_id = $paymenttermstatic->getDefaultId(); + if (empty($facture->cond_reglement_id)) { + $error++; + $confattendee->error = 'ErrorNoPaymentTermRECEPFound'; + $confattendee->errors[] = $confattendee->error; + } } - } - $resultfacture = $facture->create($user); - if ($resultfacture <= 0) { - $confattendee->error = $facture->error; - $confattendee->errors = $facture->errors; - $error++; + $resultfacture = $facture->create($user); + if ($resultfacture <= 0) { + $confattendee->error = $facture->error; + $confattendee->errors = $facture->errors; + $error++; + } else { + $confattendee->fk_invoice = $resultfacture; + $confattendee->update($user); + } + } else { + $facture->fetch($confattendee->fk_invoice); } - /* - if (!$error) { + // Add link between invoice and the attendee registration + /*if (!$error) { $facture->add_object_linked($confattendee->element, $confattendee->id); - } - */ + }*/ } if (!$error) { diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 2cd49838b78..97fe2387d8d 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -115,6 +115,8 @@ if (!$action) { if ($source == 'organizedeventregistration') { // Finding the Attendee + $attendee = new ConferenceOrBoothAttendee($db); + $invoiceid = GETPOST('ref', 'int'); $invoice = new Facture($db); @@ -123,14 +125,28 @@ if ($source == 'organizedeventregistration') { if ($resultinvoice <= 0) { setEventMessages(null, $invoice->errors, "errors"); } else { + /* + $attendeeid = 0; + $invoice->fetchObjectLinked(); $linkedAttendees = $invoice->linkedObjectsIds['conferenceorboothattendee']; if (is_array($linkedAttendees)) { $linkedAttendees = array_values($linkedAttendees); + $attendeeid = $linkedAttendees[0]; + }*/ + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."eventorganization_conferenceorboothattendee"; + $sql .= " WHERE fk_invoice = ".((int) $invoiceid); + $resql = $db->query($sql); + if ($resql) { + $obj = $db->fetch_object($resql); + if ($obj) { + $attendeeid = $obj->rowid; + } + } - $attendee = new ConferenceOrBoothAttendee($db); - $resultattendee = $attendee->fetch($linkedAttendees[0]); + if ($attendeeid > 0) { + $resultattendee = $attendee->fetch($attendeeid); if ($resultattendee <= 0) { setEventMessages(null, $attendee->errors, "errors");