1<?php
2/* Definition of the Supplier Transactions class to hold all the information for an accounts payable invoice or credit note
3*/
4
5Class SuppTrans {
6
7	var $GRNs; /*array of objects of class GRNs using the GRN No as the pointer */
8	var $GLCodes; /*array of objects of class GLCode using a counter as the pointer */
9	var $Shipts;  /*array of objects of class Shipment using a counter as the pointer */
10	var $Contracts; /*array of objects of class Contract using a counter as the pointer */
11	var $Assets; /*array of objects of class Asset using a counter as the pointer */
12	var $SupplierID;
13	var $SupplierName;
14	var $CurrCode;
15	var $TermsDescription;
16	var $Terms;
17	var $GLLink_Creditors;
18	var $GRNAct;
19	var $CreditorsAct;
20	var $InvoiceOrCredit;
21	var $ExRate;
22	var $CurrDecimalPlaces;
23	var $Comments;
24	var $TranDate;
25	var $DueDate;
26	var $SuppReference;
27	var $OvAmount;
28	var $OvGST;
29	var $GLCodesCounter=0;
30	var $ShiptCounter=0;
31	var $ContractsCounter=0;
32	var $AssetCounter=0;
33	var $TaxGroup;
34	var $LocalTaxProvince;
35	var $TaxGroupDescription;
36	var $Taxes;
37	var $Hold;
38	var $SupplierRef='';
39
40	function __construct(){
41	/*Constructor function initialises a new Supplier Transaction object */
42		$this->GRNs = array();
43		$this->GLCodes = array();
44		$this->Shipts = array();
45		$this->Contracts = array();
46		$this->Assets = array();
47		$this->Taxes = array();
48	}
49
50	function SuppTrans() {
51		self::__construct();
52	}
53
54	function GetTaxes () {
55		/*Gets the Taxes and rates applicable to the tax group of the supplier
56		and SESSION['DefaultTaxCategory'] and the taxprovince of the location that the user is setup to use*/
57
58		$SQL = "SELECT taxgrouptaxes.calculationorder,
59					taxauthorities.description,
60					taxgrouptaxes.taxauthid,
61					taxauthorities.purchtaxglaccount,
62					taxgrouptaxes.taxontax,
63					taxauthrates.taxrate
64			FROM taxauthrates INNER JOIN taxgrouptaxes ON
65				taxauthrates.taxauthority=taxgrouptaxes.taxauthid
66				INNER JOIN taxauthorities ON
67				taxauthrates.taxauthority=taxauthorities.taxid
68			WHERE taxgrouptaxes.taxgroupid=" . $this->TaxGroup . "
69			AND taxauthrates.dispatchtaxprovince=" . $this->LocalTaxProvince . "
70			AND taxauthrates.taxcatid = " . $_SESSION['DefaultTaxCategory'] . "
71			ORDER BY taxgrouptaxes.calculationorder";
72
73		$ErrMsg = _('The taxes and rates for this item could not be retrieved because');
74		$GetTaxRatesResult = DB_query($SQL,$ErrMsg);
75
76		while ($myrow = DB_fetch_array($GetTaxRatesResult)){
77
78			$this->Taxes[$myrow['calculationorder']] = new Tax($myrow['calculationorder'],
79																$myrow['taxauthid'],
80																$myrow['description'],
81																$myrow['taxrate'],
82																$myrow['taxontax'],
83																$myrow['purchtaxglaccount']);
84		}
85	} //end method GetTaxes()
86
87
88	function Add_GRN_To_Trans($GRNNo,
89								$PODetailItem,
90								$ItemCode,
91								$ItemDescription,
92								$QtyRecd,
93								$Prev_QuantityInv,
94								$This_QuantityInv,
95								$OrderPrice,
96								$ChgPrice,
97								$Complete,
98								$StdCostUnit=0,
99								$ShiptRef,
100								$JobRef,
101								$GLCode,
102								$PONo,
103								$AssetID=0,
104								$Hold=0,
105								$DecimalPlaces=2,
106								$GRNBatchNo,
107								$SupplierRef){
108
109		if ($This_QuantityInv!=0 AND isset($This_QuantityInv)){
110			$this->GRNs[$GRNNo] = new GRNs($GRNNo,
111											$PODetailItem,
112											$ItemCode,
113											$ItemDescription,
114											$QtyRecd,
115											$Prev_QuantityInv,
116											$This_QuantityInv,
117											$OrderPrice,
118											$ChgPrice,
119											$Complete,
120											$StdCostUnit,
121											$ShiptRef,
122											$JobRef,
123											$GLCode,
124											$PONo,
125											$AssetID,
126											$Hold,
127											$DecimalPlaces,
128											$GRNBatchNo,
129											$SupplierRef);
130			Return 1;
131		}
132		Return 0;
133	}
134
135	function Modify_GRN_To_Trans($GRNNo,
136									$PODetailItem,
137									$ItemCode,
138									$ItemDescription,
139									$QtyRecd,
140									$Prev_QuantityInv,
141									$This_QuantityInv,
142									$OrderPrice,
143									$ChgPrice,
144									$Complete,
145									$StdCostUnit,
146									$ShiptRef,
147									$JobRef,
148									$GLCode,
149									$Hold,
150									$SupplierRef){
151
152		if ($This_QuantityInv!=0 AND isset($This_QuantityInv)){
153			$this->GRNs[$GRNNo]->Modify($PODetailItem,
154										$ItemCode,
155										$ItemDescription,
156										$QtyRecd,
157										$Prev_QuantityInv,
158										$This_QuantityInv,
159										$OrderPrice,
160										$ChgPrice,
161										$Complete,
162										$StdCostUnit,
163										$ShiptRef,
164										$JobRef,
165										$GLCode,
166										$Hold,
167								       		$SupplierRef);
168			Return 1;
169		}
170		Return 0;
171	}
172
173	function Copy_GRN_To_Trans($GRNSrc){
174		if ($GRNSrc->This_QuantityInv!=0 && isset($GRNSrc->This_QuantityInv)){
175
176			$this->GRNs[$GRNSrc->GRNNo] = new GRNs($GRNSrc->GRNNo,
177													$GRNSrc->PODetailItem,
178													$GRNSrc->ItemCode,
179													$GRNSrc->ItemDescription,
180													$GRNSrc->QtyRecd,
181													$GRNSrc->Prev_QuantityInv,
182													$GRNSrc->This_QuantityInv,
183													$GRNSrc->OrderPrice,
184													$GRNSrc->ChgPrice,
185													$GRNSrc->Complete,
186													$GRNSrc->StdCostUnit,
187													$GRNSrc->ShiptRef,
188													$GRNSrc->JobRef,
189													$GRNSrc->GLCode,
190													$GRNSrc->PONo,
191													$GRNSrc->AssetID,
192													$GRNSrc->Hold,
193													$GRNSrc->DecimalPlaces,
194													$GRNSrc->GRNBatchNo,
195													$GRNSrc->SupplierRef);
196			Return 1;
197		}
198		Return 0;
199	}
200
201	function Add_GLCodes_To_Trans($GLCode,
202									$GLActName,
203									$Amount,
204									$Narrative,
205									$Tag){
206
207		if ($Amount!=0 AND isset($Amount)){
208			$this->GLCodes[$this->GLCodesCounter] = new GLCodes($this->GLCodesCounter,
209																$GLCode,
210																$GLActName,
211																$Amount,
212																$Narrative,
213																$Tag);
214			$this->GLCodesCounter++;
215			Return 1;
216		}
217		Return 0;
218	}
219
220	function Add_Shipt_To_Trans($ShiptRef, $Amount){
221		if ($Amount!=0){
222			$this->Shipts[$this->ShiptCounter] = new Shipment($this->ShiptCounter,
223																$ShiptRef,
224																$Amount);
225			$this->ShiptCounter++;
226			Return 1;
227		}
228		Return 0;
229	}
230
231	function Add_Asset_To_Trans($AssetID, $Amount){
232		if ($Amount!=0){
233			$this->Assets[$this->AssetCounter] = new Asset($this->AssetCounter,
234															$AssetID,
235															$Amount);
236			$this->AssetCounter++;
237			Return 1;
238		}
239		Return 0;
240	}
241
242	function Add_Contract_To_Trans($ContractRef, $Amount,$Narrative, $AnticipatedCost){
243		if ($Amount!=0){
244			$this->Contracts[$this->ContractsCounter] = new Contract($this->ContractsCounter,
245																	$ContractRef,
246																	$Amount,
247																	$Narrative,
248																	$AnticipatedCost);
249			$this->ContractsCounter++;
250			Return 1;
251		}
252		Return 0;
253	}
254	function Remove_Asset_From_Trans($AssetCounter){
255	     unset($this->Assets[$AssetCounter]);
256	}
257	function Remove_GRN_From_Trans($GRNNo){
258	     unset($this->GRNs[$GRNNo]);
259	}
260
261	function Remove_GLCodes_From_Trans($GLCodeCounter){
262	     unset($this->GLCodes[$GLCodeCounter]);
263	}
264
265	function Remove_Shipt_From_Trans($ShiptCounter){
266	     unset($this->Shipts[$ShiptCounter]);
267	}
268
269	function Remove_Contract_From_Trans($ContractID){
270	     unset($this->Contracts[$ContractID]);
271	}
272
273	function Total_GRN_Value(){
274		$TotalGRNs =0;
275		foreach ($this->GRNs as $GRN) {
276			$TotalGRNs += ($GRN->This_QuantityInv*$GRN->ChgPrice);
277		}
278		return $TotalGRNs;
279	}
280	function Total_Shipts_Value(){
281		$TotalShiptValue =0;
282		foreach ($this->Shipts as $Shipt) {
283			$TotalShiptValue += $Shipt->Amount;
284		}
285		return $TotalShiptValue;
286	}
287	function Total_GL_Value(){
288		$TotalGLValue =0;
289		foreach ($this->GLCodes as $GL) {
290			$TotalGLValue += $GL->Amount;
291		}
292		return $TotalGLValue;
293	}
294	function Total_Assets_Value(){
295		$TotalAssetValue =0;
296		foreach ($this->Assets as $Asset) {
297			$TotalAssetValue += $Asset->Amount;
298		}
299		return $TotalAssetValue;
300	}
301	function Total_Contracts_Value(){
302		$TotalContractsValue =0;
303		foreach ($this->Contracts as $Contract) {
304			$TotalContractsValue += $Contract->Amount;
305		}
306		return $TotalContractsValue;
307	}
308} /* end of class defintion */
309
310Class GRNs {
311
312/* Contains relavent information from the PurchOrderDetails as well to provide in cached form,
313all the info to do the necessary entries without looking up ie additional queries of the database again */
314
315	var $GRNNo;
316	var $PODetailItem;
317	var $ItemCode;
318	var $ItemDescription;
319	var $QtyRecd;
320	var $Prev_QuantityInv;
321	var $This_QuantityInv;
322	var $OrderPrice;
323	var $ChgPrice;
324	var $Complete;
325	var $StdCostUnit;
326	var $ShiptRef;
327	var $JobRef;
328	var $GLCode;
329	var $PONo;
330	var $Hold;
331	var $AssetID;
332	var $DecimalPlaces;
333	var $GRNBatchNo;
334	var $SupplierRef;
335
336	function __construct ($GRNNo,
337					$PODetailItem,
338					$ItemCode,
339					$ItemDescription,
340					$QtyRecd,
341					$Prev_QuantityInv,
342					$This_QuantityInv,
343					$OrderPrice,
344					$ChgPrice,
345					$Complete,
346					$StdCostUnit=0,
347					$ShiptRef,
348					$JobRef,
349					$GLCode,
350					$PONo,
351					$AssetID,
352					$Hold=0,
353					$DecimalPlaces=2,
354					$GRNBatchNo,
355					$SupplierRef=''){
356
357
358
359	/* Constructor function to add a new GRNs object with passed params */
360		$this->GRNNo = $GRNNo;
361		$this->PODetailItem = $PODetailItem;
362		$this->ItemCode = $ItemCode;
363		$this->ItemDescription = $ItemDescription;
364		$this->QtyRecd = $QtyRecd;
365		$this->Prev_QuantityInv = $Prev_QuantityInv;
366		$this->This_QuantityInv = $This_QuantityInv;
367		$this->OrderPrice =$OrderPrice;
368		$this->ChgPrice = $ChgPrice;
369		$this->Complete = $Complete;
370		$this->StdCostUnit = $StdCostUnit;
371		$this->ShiptRef = $ShiptRef;
372		$this->JobRef = $JobRef;
373		$this->GLCode = $GLCode;
374		$this->PONo = $PONo;
375		$this->AssetID = $AssetID;
376		$this->Hold = $Hold;
377		$this->DecimalPlaces = $DecimalPlaces;
378		$this->GRNBatchNo = $GRNBatchNo;
379		$this->SupplierRef = $SupplierRef;
380	}
381
382	function GRNs($GRNNo,
383					$PODetailItem,
384					$ItemCode,
385					$ItemDescription,
386					$QtyRecd,
387					$Prev_QuantityInv,
388					$This_QuantityInv,
389					$OrderPrice,
390					$ChgPrice,
391					$Complete,
392					$StdCostUnit=0,
393					$ShiptRef,
394					$JobRef,
395					$GLCode,
396					$PONo,
397					$AssetID,
398					$Hold=0,
399					$DecimalPlaces=2,
400					$GRNBatchNo,
401					$SupplierRef=''){
402		self::__construct($GRNNo,
403					$PODetailItem,
404					$ItemCode,
405					$ItemDescription,
406					$QtyRecd,
407					$Prev_QuantityInv,
408					$This_QuantityInv,
409					$OrderPrice,
410					$ChgPrice,
411					$Complete,
412					$StdCostUnit=0,
413					$ShiptRef,
414					$JobRef,
415					$GLCode,
416					$PONo,
417					$AssetID,
418					$Hold=0,
419					$DecimalPlaces=2,
420					$GRNBatchNo,
421					$SupplierRef='');
422	}
423
424	function Modify ($PODetailItem,
425					$ItemCode,
426					$ItemDescription,
427					$QtyRecd,
428					$Prev_QuantityInv,
429					$This_QuantityInv,
430					$OrderPrice,
431					$ChgPrice,
432					$Complete,
433					$StdCostUnit,
434					$ShiptRef,
435					$JobRef,
436					$GLCode,
437					$Hold,
438					$SupplierRef){
439
440	/* Modify function to edit a GRNs object with passed params */
441		$this->PODetailItem = $PODetailItem;
442		$this->ItemCode = $ItemCode;
443		$this->ItemDescription = $ItemDescription;
444		$this->QtyRecd = $QtyRecd;
445		$this->Prev_QuantityInv = $Prev_QuantityInv;
446		$this->This_QuantityInv = $This_QuantityInv;
447		$this->OrderPrice =$OrderPrice;
448		$this->ChgPrice = $ChgPrice;
449		$this->Complete = $Complete;
450		$this->StdCostUnit = $StdCostUnit;
451		$this->ShiptRef = $ShiptRef;
452		$this->JobRef = $JobRef;
453		$this->Hold = $Hold;
454		$this->GLCode = $GLCode;
455		$this->SupplierRef = $SupplierRef;
456	}
457}
458
459Class GLCodes {
460
461	Var $Counter;
462	Var $GLCode;
463	Var $GLActName;
464	Var $Amount;
465	Var $Narrative;
466	Var $Tag;
467	Var $TagName;
468
469	function __construct($Counter, $GLCode, $GLActName, $Amount, $Narrative, $Tag=0, $TagName=''){
470	/* Constructor function to add a new GLCodes object with passed params */
471		$this->Counter = $Counter;
472		$this->GLCode = $GLCode;
473		$this->GLActName = $GLActName;
474		$this->Amount = $Amount;
475		$this->Narrative = $Narrative;
476		$this->Tag = $Tag;
477
478		$TagResult=DB_query("SELECT tagdescription from tags where tagref='" . $Tag . "'");
479		$TagMyrow=DB_fetch_array($TagResult);
480		if ($Tag==0) {
481			$this->TagName=_('None');
482		} else {
483			$this->TagName=$TagMyrow['tagdescription'];
484		}
485	}
486
487	function GLCodes($Counter, $GLCode, $GLActName, $Amount, $Narrative, $Tag=0, $TagName=''){
488		self::__construct($Counter, $GLCode, $GLActName, $Amount, $Narrative, $Tag=0, $TagName='');
489	}
490
491
492}
493
494Class Shipment {
495
496	Var $Counter;
497	Var $ShiptRef;
498	Var $Amount;
499
500	function __construct($Counter, $ShiptRef, $Amount){
501		$this->Counter = $Counter;
502		$this->ShiptRef = $ShiptRef;
503		$this->Amount = $Amount;
504	}
505
506	function Shipment ($Counter, $ShiptRef, $Amount){
507		self::__construct($Counter, $ShiptRef, $Amount);
508	}
509}
510
511Class Asset {
512
513	Var $Counter;
514	Var $AssetID;
515	Var $Description;
516	Var $CostAct;
517	Var $Amount;
518
519	function __construct($Counter, $AssetID, $Amount){
520		$this->Counter = $Counter;
521		$this->AssetID = $AssetID;
522		$this->Amount = $Amount;
523
524		$result = DB_query("SELECT fixedassets.description,
525									fixedassetcategories.costact
526							FROM fixedassets INNER JOIN fixedassetcategories
527							ON fixedassets.assetcategoryid=fixedassetcategories.categoryid
528							WHERE assetid='" . $AssetID . "'");
529		$AssetRow = DB_fetch_array($result);
530		$this->Description = $AssetRow['description'];
531		$this->CostAct = $AssetRow['costact'];
532	}
533
534	function Asset ($Counter, $AssetID, $Amount){
535		self::__construct($Counter, $AssetID, $Amount);
536	}
537}
538
539Class Contract {
540
541	Var $Counter;
542	Var $ContractRef;
543	Var $Amount;
544	Var $Narrative;
545	Var $AniticipatedCost;
546
547	function __construct($Counter, $ContractRef, $Amount,$Narrative,$AnticipatedCost){
548		$this->Counter = $Counter;
549		$this->ContractRef = $ContractRef;
550		$this->Amount = $Amount;
551		$this->Narrative = $Narrative;
552		$this->AnticipatedCost = $AnticipatedCost;
553	}
554
555	function Contract ($Counter, $ContractRef, $Amount,$Narrative,$AnticipatedCost){
556		self::__construct($Counter, $AssetID, $Amount,$Narrative,$AnticipatedCost);
557	}
558}
559
560
561Class Tax {
562	Var $TaxCalculationOrder;  /*the index for the array */
563	Var $TaxAuthID;
564	Var $TaxAuthDescription;
565	Var $TaxRate;
566	Var $TaxOnTax;
567	Var $TaxGLCode;
568	Var $TaxOvAmount;
569
570	function __construct ($TaxCalculationOrder,
571					$TaxAuthID,
572					$TaxAuthDescription,
573					$TaxRate,
574					$TaxOnTax,
575					$TaxGLCode){
576
577		$this->TaxCalculationOrder = $TaxCalculationOrder;
578		$this->TaxAuthID = $TaxAuthID;
579		$this->TaxAuthDescription = $TaxAuthDescription;
580		$this->TaxRate =  $TaxRate;
581		$this->TaxOnTax = $TaxOnTax;
582		$this->TaxGLCode = $TaxGLCode;
583	}
584
585	function Tax ($TaxCalculationOrder,
586					$TaxAuthID,
587					$TaxAuthDescription,
588					$TaxRate,
589					$TaxOnTax,
590					$TaxGLCode){
591		self::__construct($TaxCalculationOrder,
592					$TaxAuthID,
593					$TaxAuthDescription,
594					$TaxRate,
595					$TaxOnTax,
596					$TaxGLCode);
597	}
598
599}
600?>
601