</tr>
   	<tr height="20px">
		<td  class="form_head">
			<?php echo gettext("CREATION DATE") ?> :
		</td>
		<td class="tableBodyRight"  background="../Public/templates/default/images/background_cells.gif" width="70%">
			<?php echo $payment['date']?> 
		</td>
	</tr>
   <tr height="20px">
		<td  class="form_head">
			<?php echo gettext("PAYMENT TYPE") ?> :
		</td>
		<td class="tableBodyRight"  background="../Public/templates/default/images/background_cells.gif" width="70%">
			<?php 
			$list_type = Constants::getRefillType_List();
			echo $list_type[$payment['payment_type']][0];?> 
		</td>
   </tr>
   <tr height="20px">
		<td  class="form_head">
			<?php echo gettext("DESCRIPTION ") ?> :
		</td>
		<td class="tableBodyRight"  background="../Public/templates/default/images/background_cells.gif" width="70%">
			<?php echo $payment['description']?> 
		</td>
	</tr>
   	<?php if(!empty($payment['id_logrefill'])){ ?>
   	<tr height="20px">
		<td  class="form_head">
			<?php echo gettext("LINK REFILL") ?> :
示例#2
0
	/**
     * Function create_refill
     * @public
     */
	static public function create_refill_after_payment()
	{ 
		global $A2B;
		$FormHandler = FormHandler::GetInstance();
		$processed = $FormHandler->getProcessed();
		if ($processed['added_refill']==1) {
			$id_payment = $FormHandler -> RESULT_QUERY;
			// CREATE REFILL
			$field_insert = "date, credit, card_id ,refill_type, description";
			$date = $processed['date'];
			$credit = $processed['payment'];
			$card_id = $processed['card_id'];
			$refill_type= $processed['payment_type'];
			$description = $processed['description'];
            $card_table = new Table('cc_card','vat');
            $card_clause = "id = ".$card_id;
            $card_result = $card_table -> Get_list($FormHandler->DBHandle, $card_clause, 0);
            if(!is_array($card_result)||empty($card_result[0][0])||!is_numeric($card_result[0][0]))
            	$vat=0;
            else
            	$vat = $card_result[0][0];
            $credit_without_vat = $credit / (1+$vat/100);
            
			$value_insert = " '$date' , '$credit_without_vat', '$card_id','$refill_type', '$description' ";
			$instance_sub_table = new Table("cc_logrefill", $field_insert);
			$id_refill = $instance_sub_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");	
			// REFILL CARD .. UPADTE CARD
			$instance_table_card = new Table("cc_card");
			$param_update_card = "credit = credit + '".$credit_without_vat."'";
			$clause_update_card = " id='$card_id'";
			$instance_table_card -> Update_table ($FormHandler->DBHandle, $param_update_card, $clause_update_card, $func_table = null);
			//LINK THE REFILL TO THE PAYMENT .. UPADTE PAYMENT
			$instance_table_pay = new Table("cc_logpayment");
			$param_update_pay = "id_logrefill = '".$id_refill."'";
			$clause_update_pay = " id ='$id_payment'";
			$instance_table_pay-> Update_table ($FormHandler->DBHandle, $param_update_pay, $clause_update_pay, $func_table = null);
		
			// Create invoice associated
		
			// CREATE AND UPDATE REF NUMBER
			$list_refill_type=Constants::getRefillType_List();
			$refill_type = $processed['payment_type'];
			$year = date("Y");
			$invoice_conf_table = new Table('cc_invoice_conf','value');
			$conf_clause = "key_val = 'count_$year'";
			$result = $invoice_conf_table -> Get_list($FormHandler->DBHandle, $conf_clause, 0);
			if (is_array($result) && !empty($result[0][0])) {
				// update count
				$count =$result[0][0];
				if(!is_numeric($count)) $count=0;
				$count++;
				$param_update_conf = "value ='".$count."'";
				$clause_update_conf = "key_val = 'count_$year'";
				$invoice_conf_table -> Update_table ($FormHandler->DBHandle, $param_update_conf, $clause_update_conf, $func_table = null);
			} else {
				// insert newcount
				$count=1;
				$QUERY= "INSERT INTO cc_invoice_conf (key_val ,value) VALUES ( 'count_$year', '1');";
				$invoice_conf_table -> SQLExec($FormHandler->DBHandle,$QUERY);
			}
			$field_insert = "date, id_card, title ,reference, description,status,paid_status";
			if($refill_type!=0) {
				$title = $list_refill_type[$refill_type][0]." ".gettext("REFILL");
			} else {
				$title = gettext("REFILL");
			}
			$description = gettext("Invoice for refill");
			$reference = $year.sprintf("%08d",$count);
			$value_insert = " '$date' , '$card_id', '$title','$reference','$description','1','1' ";
			$instance_table = new Table("cc_invoice", $field_insert);
			$id_invoice = $instance_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");
			//add payment to this invoice
			$field_insert = "id_invoice, id_payment";
			$value_insert = "'$id_invoice' , '$id_payment'";
			$instance_table = new Table("cc_invoice_payment", $field_insert);
			$instance_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null);
			//load vat of this card
			if (!empty($id_invoice) && is_numeric($id_invoice)) {
				$description = $processed['description'];
				$field_insert = "date, id_invoice ,price,vat, description";
				$instance_table = new Table("cc_invoice_item", $field_insert);
				$value_insert = " '$date' , '$id_invoice', '$credit_without_vat','$vat','$description' ";
				$instance_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");
			}
		}
		
		if($processed['added_commission']==1) {
			$card_id = $processed['card_id'];
			$table_transaction = new Table();
			$result_agent = $table_transaction -> SQLExec($FormHandler->DBHandle,"SELECT cc_card_group.id_agent FROM cc_card LEFT JOIN cc_card_group ON cc_card_group.id = cc_card.id_group WHERE cc_card.id = $card_id");
			
			if (is_array($result_agent)&& !is_null($result_agent[0]['id_agent']) && $result_agent[0]['id_agent']>0 ) {
				
				// test if the agent exist and get its commission
				$id_agent = $result_agent[0]['id_agent'];
				// update refill & payment to keep a trace of agent in the timeline
				$table_refill = new Table("cc_logrefill");
				$table_payment = new Table("cc_logpayment");
				$param_update = "agent_id = '".$id_agent."'";
				if(!empty($id_refill)){
					$clause_update_refill_agent = " id ='$id_refill'";
					$table_refill-> Update_table ($FormHandler->DBHandle, $param_update, $clause_update_refill_agent, $func_table = null);
				}
				$clause_update_payment_agent = " id ='$id_payment'";
				$table_payment-> Update_table ($FormHandler->DBHandle, $param_update, $clause_update_payment_agent, $func_table = null);
				
				$agent_table = new Table("cc_agent", "commission");
				$agent_clause = "id = ".$id_agent;
				$result_agent= $agent_table -> Get_list($FormHandler->DBHandle,$agent_clause);
				
				if (is_array($result_agent) && is_numeric($result_agent[0]['commission']) && $result_agent[0]['commission']>0) {
					$field_insert = "id_payment, id_card, amount,description,id_agent";
					$commission = a2b_round($processed['payment'] * ($result_agent[0]['commission']/100));
					$description_commission = gettext("AUTOMATICALY GENERATED COMMISSION!");
					$description_commission.= "\nID CARD : ".$card_id;
					$description_commission.= "\nID PAYMENT : ".$id_payment;
					$description_commission.= "\nPAYMENT AMOUNT: ".$amount_paid;
					$description_commission.= "\nCOMMISSION APPLIED: ".$result_agent[0]['commission'];
					$value_insert = "'".$id_payment."', '$card_id', '$commission','$description_commission','$id_agent'";
					$commission_table = new Table("cc_agent_commission", $field_insert);
					$id_commission = $commission_table -> Add_table ($FormHandler->DBHandle, $value_insert, null, null,"id");
					$table_agent = new Table('cc_agent');
					$param_update_agent = "com_balance = com_balance + '".$commission."'";
					$clause_update_agent = " id='".$id_agent."'";
					$table_agent -> Update_table ($FormHandler->DBHandle, $param_update_agent, $clause_update_agent, $func_table = null);
				}
			}	
		}
	}