bobs@sectorlink Posted October 14, 2015 Report Posted October 14, 2015 I'm doing a test method for invoices, but it echos Failed and I see no new invoices. What parameters am I missing or doing wrong? Here is the method inside of my plugin: public function testing() { Loader::loadModels($this, array("Invoices")); $now = date("Y-m-d H:m:s"); $a_i['client_id'] = 1500; $a_i['date_billed'] = $now; $a_i['date_due'] = $now; // The date the invoice is due // $a_i['date_closed'] = ''; // The date the invoice was closed $a_i['date_autodebit'] = $now; // The date the invoice should be autodebited $a_i['status'] = 'void'; // 'active','draft','proforma', or 'void' $a_i['currency'] = 'USD'; $a_i['note_public'] = 'Pub note1.'; $a_i['note_private'] = 'Pri note1.'; $a_i['term'] = ''; // Leave blank for non recurring invoice! $a_i['delivery'] = array('method'=>'email'); // $a_line['service_id'] = ''; // The service ID attached to this line item (optional) $a_line['description'] = 'Test #1 worked.'; $a_line['qty'] = 1; $a_line['amount'] = 2.33; $lines[] = $a_line; $a_line2['description'] = 'Line Item #2 worked.'; $a_line2['qty'] = 2; $a_line2['amount'] = 1.33; $lines[] = $a_line2; $a_i['lines'] = $lines; $invoice_id = $this->Invoices->add($a_i); if (isset($invoice_id) && $invoice_id > 0) { echo "Worked # " . $invoice_id; } else { echo "Failed!!!"; } } Quote
bobs@sectorlink Posted October 14, 2015 Author Report Posted October 14, 2015 I found some examples by searching for "Invoices->Add(", with my IDE. I changed now to: $now = date("c"); I see that delivery should have a numerically indexed array of delivery methods: $a_i['delivery'] = array(0=>'email'); Form looking at the invoice method and comments, but still I get the message: Failed!!! Quote
Tyson Posted October 14, 2015 Report Posted October 14, 2015 Sounds like you're working a little too hard. Try to simplify your test a bit and check for errors that are generated while consulting the documentation regarding expected input, e.g.: public function testing() { Loader::loadModels($this, array("Invoices")); $now = date('c'); $vars = array( 'client_id' => 1500, 'date_billed' => $now, 'date_due' => $now, 'date_autodebit' => $now, 'status' => 'void', 'currency' => 'USD', 'note_public' => 'Pub note1', 'note_privote' => 'Pri note1.', 'term' => '', 'delivery' => array('email'), 'lines' => array( array( 'description' => 'Test #1 worked.', 'qty' => 1, 'amount' => '2.33', ), array( 'description' => 'Line Item #2 worked.', 'qty' => 2, 'amount' => '1.33' ) ) ); $invoice_id = $this->Invoices->add($vars); // Errors? if (($errors = $this->Invoices->errors())) { print_r($errors); } else { echo 'Worked #' . $invoice_id; } } Quote
bobs@sectorlink Posted October 14, 2015 Author Report Posted October 14, 2015 Thanks for the Error handler, I see the issue is with my client_id - the system says it is incorrect. public function testing() { Loader::loadModels($this, array("Invoices")); $now = date("c"); $lines[] = array( 'description' => 'Test #1 worked.', 'qty' => 1, 'amount' => '2.33', ); $lines[] = array( 'description' => 'Line Item #2 worked.', 'qty' => 2, 'amount' => '1.33' ); $vars = array( 'client_id' => '1500', 'date_billed' => $now, 'date_due' => $now, 'date_autodebit' => $now, 'status' => 'void', 'currency' => 'USD', 'note_public' => 'Pub note1', 'note_privote' => 'Pri note1.', 'term' => '', 'delivery' => array('email'), 'lines' => $lines ); $invoice_id = $this->Invoices->add($vars); // Errors? if (($errors = $this->Invoices->errors())) { print_r($errors); } else { echo 'Worked #' . $invoice_id; } } Quote
Tyson Posted October 14, 2015 Report Posted October 14, 2015 Thanks for the Error handler, I see the issue is with my client_id - the system says it is incorrect. $vars = array( 'client_id' => '1500', Client ID is the system-level (auto-increment) ID from the `clients` table of the database. The number "1500" is the formulated ID code, derived from company settings, which is generally only useful for display purposes. Try using "1" instead of "1500" for the client_id. Quote
bobs@sectorlink Posted October 14, 2015 Author Report Posted October 14, 2015 Thanks, that did the trick. Have a Great Day, Sincerely, Bob Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.