Ejemplo n.º 1
0
	public function loadTours()
	{
 		$model=CashboxChangeRequests::model()->with('user')->findAll('(approvedBy IS NULL) AND (reject=0)');
		if($model===null)
			throw new CHttpException(404,'The cashbox model does not exist.');
		return $model;
	}
Ejemplo n.º 2
0
	public function createpdf($sched)
	{
		
		$id_control = Yii::app()->user->id;
            $guide = User::model()->with('contact_ob')->findByPk($id_control);
		$date_format = strtotime($sched->date);
		$date_bd = date('Y-m-d',$date_format);
		$dt =$date_bd.' '.$sched->starttime;
		$tour = SegTourroutes::model()->findByPk($sched->tourroute_id);
		$mails=array();
		$fn='.'; $ln='.';
		if((!is_null($guide->contact_ob['firstname'])) && $guide->contact_ob['firstname']!=''){$fn = $guide->contact_ob['firstname']{0};}else{$fn='0';}
		if((!is_null($guide->contact_ob['surname'])) && $guide->contact_ob['surname']!=''){$ln = $guide->contact_ob['surname']{0};}else{$ln='0';}
		$c = $tour->city['seg_cityname']{0};
		$year = date('y',time());
                $b = $tour->city['seg_cityname']{0};
 		$num=0;
		$criteria_i = new CDbCriteria;
		$criteria_i->condition = 'guide1_id=:guide1_id AND openTour=:openTour';
		$criteria_i->params = array(':guide1_id'=>$id_control,'openTour'=>1);
		$schedall = SegScheduledTours::model()->findAll($criteria_i);
		foreach($schedall as $item){
				$year_item = date('y',$item->date_now);
				if($year_item == $year){
					$num++;
				}
			}
		$num = $num+1;
//		$sched->GN_string = $fn.$ln.$c.'/'.$id_control.'/'.$year.'/'.$num;		
		$sched->GN_string = $fn.$ln.$c.'/'.$year.'/'.$num;		
		$sched->openTour = 1;//create pdf
			//tourroutes
		$criteria_tourroutes = new CDbCriteria;
		$criteria_tourroutes->condition = 'usersid=:usersid AND tourroutes_id=:tourroutes_id';
		$criteria_tourroutes->params = array(':usersid'=>$sched->user_ob->id,'tourroutes_id'=>$tour->id_tour_categories);
		$tourroutes = SegGuidesTourroutes::model()->find($criteria_tourroutes);
		$vat= Yii::app()->db->createCommand("SELECT value from mainoptions where name='Vat'")->queryScalar();
		$firma= Yii::app()->db->createCommand("SELECT value from mainoptions where name='Firma'")->queryScalar();
		$sum_itog=0;
		$sum_bar=0;
		$count_cust=0;
        $max= Yii::app()->db->createCommand("SELECT max(InvoiceNumber) from seg_guidestourinvoices where cityid=".$tour->cityid)->queryScalar();
        $max_i = $max+1;
        foreach ($sched->guidestourinvoices as $invoice) 
       {
            $model=$invoice->guidestourinvoicescustomers;
            $overAllIncome=0;
            $cashIncome=0;
            $count_inv=0;
            $invoice_id =  $invoice->idseg_guidesTourInvoices;
            for($k=0;$k<count($model);$k++){
                $kk=$model[$k]->idseg_guidesTourInvoicesCustomers;
                    if($model[$k]->isPaid == 1)  $count_cust++;
                    $count_inv++;
                }
               $invoice->status = 1;
               $sum_itog += $invoice->overAllIncome;
               $sum_bar += $invoice->cashIncome;
               $invoice->TA_string = 'TA'.$b.$year.'/'.$max_i;
               $invoice->InvoiceNumber =$max_i;
               $invoice->save();
               $tmpname=$this->doPDF($sched, $invoice);
               $mails[]=array($invoice->contact['email'],$tmpname);
        }
		$sum_vat = round($sum_itog*(1-1/($vat/100+1)),2);
		$sum_b_vat = $sum_itog - $sum_vat;
	
		$cifra = $count_cust - $tourroutes->guest_variable;
		if($cifra<=0){$cifra=0;}//turists >
		$gonorar = $tourroutes->base_provision+$cifra*$tourroutes->guestsMinforVariable;//summa gonorar
		$gonorar_vat = $gonorar*(1-1/($vat/100+1));
		$gonorar_vat = number_format($gonorar_vat, 2, '.', ' ');

		$cashnew=new CashboxChangeRequests;
		$cashnew->id_users=$id_control;
		$cashnew->approvedBy=$id_control;
		$cashnew->delta_cash = $sum_bar;
		$datetime = date('Y-m-d H:i:s', time());
		$cashnew->approval_date=$datetime;
		$cashnew->id_type = 1;
		$cashnew->sched_user_id = $sched->idseg_scheduled_tours;
		$cashnew->save();
		$cashnew1 = new CashboxChangeRequests;
		$cashnew1->id_users=$id_control;
		$cashnew1->approvedBy=$id_control;
		$cashnew1->approval_date=$datetime;
		$cashnew1->sched_user_id = $sched->idseg_scheduled_tours;
		$cashnew1->delta_cash = -$gonorar;
		$cashnew1->id_type = 2;
		$cashnew1->save();
            $cashnow=$this->cashsum;
		//************************************PDF CREATE***************************************************//
		//$pdf->SetFont('freeserif', '', 14);
		$printOrders = null;
		$forpdf=array();
		$forpdf['gonorar_vat']=$gonorar_vat;
		$forpdf['firma']=$firma;
		$forpdf['cifra']=$cifra;
		$forpdf['base_provision'] = number_format($tourroutes->base_provision, 2, '.', ' ');
		$forpdf['guestsMinforVariable'] = number_format($tourroutes->guestsMinforVariable, 2, '.', ' ');
		$forpdf['gonorar_zero'] = number_format($gonorar, 2, '.', ' ');
		$forpdf['cashBefore'] = number_format($cashnow, 2, '.', ' '); 
		$forpdf['sum_bar_zero'] = number_format($sum_bar, 2, '.', ' '); 
		$forpdf['cashnow_zero'] = number_format($cashnow-$gonorar+$sum_bar, 2, '.', ' '); 
		$forpdf['delta_cash_zero'] = number_format($sum_bar-$gonorar, 2, '.', ' ');
		$forpdf['cashnow_enter'] = number_format($cashnow+$gonorar-$sum_bar, 2, '.', ' ');
		$name_pdf2=$this->doPDF($sched, $forpdf);
//		var_dump($mails);return false;
		$sched->additional_info2=$name_pdf2;
		$sched->save();
             $message="Dear sirs, \n The invoice from Cherry tours.";
                $subject = "The invoice from Cherry tours";
				foreach ($mails as $value) {
        			$this->sendMail($value[0],$subject,$message, __DIR__.'/../../../../filespdf/'.$value[1].'.pdf');
						unlink(__DIR__.'/../../../../filespdf/'.$value[1].'.pdf');
			}
	        $this->redirect( Yii::app()->createUrl('/filespdf/'.$name_pdf2.'.pdf') );
	}