ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilERPDebtor_eco.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
33 require_once './Services/Payment/classes/class.ilERPDebtor.php';
34 require_once './Services/Payment/classes/class.ilERP_eco.php';
35 
37 {
38  private $set;
39  private $erp;
40  private $invH;
41 
45  public function __construct()
46  {
47 
48  $this->erp = ilERP_eco::_getInstance();
49  $this->set = $this->erp->getSettings();
50 
52 
53  }
54 
55 
60  public function getDebtorByNumber($number)
61  {
62  unset($this->handle);
63  if (!$this->erp->connection_ok) $this->erp->connect();
64  try
65  {
66  $this->handle = $this->erp->client->Debtor_FindByNumber(array('number' => $number))->Debtor_FindByNumberResult;
67  }
68  catch (Exception $e)
69  {
70  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage());
71  }
72  if (isset($this->handle)) return true; else return false;
73  }
74 
75 
76  public function setDebtorGroup($number=1)
77  {
78  $this->dgh = $this->erp->client->debtorGroup_FindByNumber(
79  array('number' => $number))->DebtorGroup_FindByNumberResult;
80  }
81 
82 
83 
88  public function createDebtor($number)
89  {
90  $cust = $this->getAll();
91  $deb = new stdClass();
92  $deb->Number = $number;
93 
94 
95  $this->setDebtorGroup(); // cheating
96 
97  $deb->DebtorGroupHandle = $this->dgh;
98  $deb->Name = $cust['name'];
99  $deb->Email = $cust['email'];
100  $deb->Address = $cust['address'];
101  $deb->PostalCode = $cust['postalcode'];
102  $deb->City = $cust['city'];
103  $deb->Country = $cust['country'];
104  $deb->TelephoneAndFaxNumber = $cust['phone'];
105  $deb->Website = $cust['website'];
106 
107  $deb->VatZone = "HomeCountry";
108  $deb->IsAccessible = true;
109 
110  $deb->CurrencyHandle = new stdClass();
111  $deb->CurrencyHandle->Code = $this->set['code'];
112 
113  $deb->TermOfPaymentHandle = new stdClass();
114  $deb->TermOfPaymentHandle->Id = $this->set['terms'];
115 
116  $deb->LayoutHandle = new stdClass();
117  $deb->LayoutHandle->Id = $this->set['layout'];
118 
119  //if (!$this->erp->connection_ok) $this->erp->connect();
120  try
121  {
122  $this->handle = $this->erp->client->Debtor_CreateFromData(array('data' => $deb))->Debtor_CreateFromDataResult;
123  }
124  catch (Exception $e)
125  {
126  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage() . " " . print_r($deb,true));
127  }
128  }
129 
130  public function getDebtorGroup()
131  {
132  $this->dgh = $this->erp->client->debtorGroup_FindByNumber(array('number' => 1))->DebtorGroup_FindByNumberResult;
133  }
134 
135 
136 
140  public function setEAN($ean)
141  {
142  if (!strlen($ean)==13)
143  $this->setError("(cannot set EAN number. Must be 13 digits not '" . $ean .".");
144  else
145  try
146  {
147  $this->erp->client->Debtor_SetEan(array('debtorHandle' => $this->handle, 'value' => $ean));
148  return true;
149  }
150  catch (Exception $e)
151  {
152  throw new ilERPException("(setEan " . $ean . ") " . $e->getMessage());
153  }
154  return false;
155  }
156 
160  public function createInvoice()
161  {
162  if (!$this->erp->connection_ok) $this->erp->connect();
163  try
164  {
165  $this->invH = $this->erp->client->CurrentInvoice_Create(array('debtorHandle' => $this->handle))->CurrentInvoice_CreateResult;
166  }
167  catch (Exception $e)
168  {
169  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage());
170  }
171  }
172 
178  public function createInvoiceLine( $product, $desc, $quantity, $unetprice )
179  {
180  if (!isset($this->invH)) throw new ilERPException(__FILE__ . ":" . __LINE__ . " No Invoice Handle set.");
181  else
182  {
183  if (!$this->erp->connection_ok) $this->erp->connect();
184  try
185  {
186  $productH = $this->getProduct( $this->set['product'] );
187  $lineH = $this->erp->client->CurrentInvoiceLine_Create(
188  array('invoiceHandle' => $this->invH ))->CurrentInvoiceLine_CreateResult;
189 
190  $this->erp->client->CurrentInvoiceLine_SetProduct(
191  array('currentInvoiceLineHandle' => $lineH, 'valueHandle' => $productH ));
192  $this->erp->client->CurrentInvoiceLine_SetDescription(
193  array('currentInvoiceLineHandle' => $lineH, 'value' => $desc ));
194  $this->erp->client->CurrentInvoiceLine_SetQuantity(
195  array('currentInvoiceLineHandle' => $lineH, 'value' => (float) $quantity ));
196  $this->erp->client->CurrentInvoiceLine_SetUnitNetPrice(
197  array('currentInvoiceLineHandle' => $lineH, 'value' => $unetprice ));
198  }
199  catch (Exception $e)
200  {
201  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage());
202  }
203  }
204  }
205 
210  public function bookInvoice()
211  {
212  if (!$this->erp->connection_ok) $this->erp->connect();
213  try
214  {
215  $this->erp->client->CurrentInvoice_SetIsVatIncluded(
216  array('currentInvoiceHandle' => $this->invH, 'value' => 0));
217  $v = $this->erp->client->CurrentInvoice_Book(
218  array('currentInvoiceHandle' => $this->invH))->CurrentInvoice_BookResult;
219  $this->invoice_booked = true;
220  $this->invoice_number = $v->Number;
221  return $v;
222  }
223  catch (Exception $e)
224  {
225  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage());
226  }
227  }
228 
229  private function getProduct($product = null)
230  {
231  $product = $this->set['product'];
232  if (!$this->erp->connection_ok) $this->erp->connect();
233  try
234  {
235  return $this->erp->client->Product_FindByNumber(array('number' => $product))->Product_FindByNumberResult;
236  }
237  catch (Exception $e)
238  {
239  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage());
240 
241  }
242  }
243 
244 
248  public function getInvoicePDF($v)
249  {
250  if (!($this->invoice_booked)) throw new ilERPException("(getInvoicePDF) Cannot generate PDF of unbooked invoice.");
251  if (!$this->erp->connection_ok) $this->erp->connect();
252  try
253  {
254  $bytes = $this->erp->client->Invoice_GetPdf( array('invoiceHandle' => $v))->Invoice_GetPdfResult;
255  }
256  catch (Exception $e)
257  {
258  throw new ilERPException(__FILE__ . ":" . __LINE__ . " " . $e->getMessage());
259  }
260  return $bytes;
261  }
262 
263 
264 }
265 
266 ?>