Exemple #1
0
 /**
  * Custom add method to add an invoice. Needs a contact for each invocie else 
  * do not add the invoice
  * @param $evtcl -- Object  
  */
 function addInvoice(EventControler $evtcl)
 {
     $_SESSION['in_page_message'] = '';
     $rec_value = $evtcl->recurrent;
     $add_invoice = false;
     $do_contact = new Contact();
     $concat_name_in_address = '';
     if ($evtcl->fields["due_date"] == '') {
         $this->due_date = date('Y-m-d');
     } else {
         $this->due_date = $evtcl->fields["due_date"];
     }
     if ($evtcl->idcontact) {
         $idcontact = $evtcl->idcontact;
         $add_invoice = true;
         $do_contact->getId($idcontact);
     } else {
         $cont_name = $evtcl->contact;
         if ($cont_name != '') {
             $do_Contact_View = new ContactView();
             $do_contact->addNew();
             $do_contact->firstname = $cont_name;
             $do_contact->iduser = $_SESSION['do_User']->iduser;
             $do_contact->add();
             $idcontact = $do_contact->getPrimaryKeyValue();
             $do_Contact_View->setUser($_SESSION['do_User']->iduser);
             $do_contact->getId($idcontact);
             $concat_name_in_address = $do_contact->firstname;
             $do_Contact_View->addFromContact($do_contact);
             $do_Contact_View->updateFromContact($do_contact);
             if ($idcontact) {
                 $add_invoice = true;
                 $do_cont_addr = new ContactAddress();
                 $do_cont_addr->addNew();
                 $do_cont_addr->idcontact = $idcontact;
                 $do_cont_addr->address = $evtcl->fields["invoice_address"];
                 $do_cont_addr->address_type = 'Work';
                 if (strlen($evtcl->fields["invoice_address"]) > 0) {
                     $do_cont_addr->add();
                 }
             }
         }
     }
     if ($add_invoice) {
         // Keep the idcontact in case there is an idcompany
         if ($do_contact->idcompany != '' && !empty($do_contact->idcompany)) {
             $this->idcompany = $do_contact->idcompany;
         }
         //$this->num = $this->getUniqueInvoiceNum();
         $this->num = time();
         $this->iduser = $_SESSION['do_User']->iduser;
         $this->idterms = $evtcl->fields["idterms"];
         $this->description = $evtcl->fields["description"];
         $this->discount = $evtcl->fields["discount"];
         $this->tax = $evtcl->fields["tax"];
         $this->datecreated = date("Y-m-d");
         $this->idcontact = $idcontact;
         $this->status = 'Quote';
         $this->invoice_note = $evtcl->fields["invoice_note"];
         $this->invoice_term = $evtcl->fields["invoice_term"];
         if ($concat_name_in_address == '') {
             $this->invoice_address = $evtcl->fields["invoice_address"];
         } else {
             $this->invoice_address = $concat_name_in_address . '<br />' . $evtcl->fields["invoice_address"];
         }
         $this->add();
         $this->idinvoice = $this->getPrimaryKeyValue();
         // If the user set to have the ivoice added as recurrent Invoice then add
         if ($evtcl->setRec == 'Yes') {
             if (!empty($rec_value) && preg_match('/^[0-9]+$/', $rec_value) && $rec_value != 0) {
                 // Add to recurrent
                 $_SESSION['RecurrentInvoice']->addRecurrentInvoice($this->getPrimaryKeyValue(), $evtcl->recurrent, $evtcl->frequency, date("Y-m-d"));
             } else {
                 $_SESSION['in_page_message'] = _("Recurrent Value is not correct.To set as Recurrent edit the invoice and enter numeric value");
             }
         }
     } else {
         $_SESSION['in_page_message'] = _("Invoice could be created. Possible reason Contact Missing.");
         $evtcl->setDisplayNext(new Display('invoices.php'));
     }
 }
Exemple #2
0
 $ContactWebsite = $_SESSION['do_contact']->getChildContactWebsite();
 $ContactWebsiteAdd = new ContactWebsite();
 if ($ContactWebsite->getNumRows()) {
     while ($ContactWebsite->next()) {
         $ContactWebsiteAdd->addNew();
         $ContactWebsiteAdd->idcontact = $idcontact_inserted;
         $ContactWebsiteAdd->website = $ContactWebsite->website;
         $ContactWebsiteAdd->website_type = $ContactWebsite->website_type;
         $ContactWebsiteAdd->add();
     }
 }
 $ContactAddress = $_SESSION['do_contact']->getChildContactAddress();
 $ContactAddressAdd = new ContactAddress();
 if ($ContactAddress->getNumRows()) {
     while ($ContactAddress->next()) {
         $ContactAddressAdd->addNew();
         $ContactAddressAdd->idcontact = $idcontact_inserted;
         $ContactAddressAdd->address_type = $ContactAddress->address_type;
         $ContactAddressAdd->address = $ContactAddress->address;
         $ContactAddressAdd->add();
     }
 }
 $do_cont_ref = new Contact();
 $do_cont_ref->getId($idcontact_inserted);
 $do_contact_view = new ContactView();
 $do_contact_view->setUser($_SESSION['do_User']->iduser);
 $do_contact_view->addFromContact($do_cont_ref);
 $do_contact_view->updateFromContact($do_cont_ref);
 $do_cont_ref->free();
 $_SESSION['hcard_idcontact'] = '';
 header("Location: /Contact/" . $idcontact_inserted);