117 lines
4.4 KiB
PHP
117 lines
4.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
use App;
|
||
|
|
use Illuminate\Support\Facades\Storage;
|
||
|
|
use CpChart\Data;
|
||
|
|
use CpChart\Image;
|
||
|
|
use App\Traits\CouponTrait;
|
||
|
|
use App\Traits\GraphTrait;
|
||
|
|
use App\Campagne;
|
||
|
|
use App\Site;
|
||
|
|
use App\Coupon;
|
||
|
|
use Datetime;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class ExportController extends Controller
|
||
|
|
{
|
||
|
|
use CouponTrait;
|
||
|
|
use GraphTrait;
|
||
|
|
/**
|
||
|
|
* Handle the incoming request.
|
||
|
|
*
|
||
|
|
* @param \Illuminate\Http\Request $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function show(Request $request)
|
||
|
|
{
|
||
|
|
$coupon = Coupon::where(['coupon_code' => 2958008200723])->first();
|
||
|
|
$campid = 101;
|
||
|
|
$startdate = '27-02-2019';
|
||
|
|
$enddate = '11-03-2019';
|
||
|
|
|
||
|
|
$labels = $this->getLabelsForStats($startdate, $enddate);
|
||
|
|
|
||
|
|
$dataCoupon = $this->getDataForCoupon($labels, $campid, $coupon);
|
||
|
|
|
||
|
|
|
||
|
|
$sites = Site::all();
|
||
|
|
$startdate = new DateTime("first day of last month");
|
||
|
|
$startdate = $startdate->format('Y-m-d');
|
||
|
|
$enddate = date('Y-m-d');
|
||
|
|
// $pdf = App::make('dompdf.wrapper');
|
||
|
|
|
||
|
|
// $myData = new Data();
|
||
|
|
// $myData->addPoints($dataCoupon,"My Serie 1");
|
||
|
|
// $myData->addPoints($labels,"My Serie 2");
|
||
|
|
// $myData->setAxisName(0,"Coupons");
|
||
|
|
// $myData->setAbscissa("My Serie 2");
|
||
|
|
|
||
|
|
// $myPicture = new Image(700,230,$myData);
|
||
|
|
// $myPicture->setGraphArea(60,40,670,190);
|
||
|
|
// $myPicture->setFontProperties(array("FontSize"=>6));
|
||
|
|
// $myPicture->drawScale(array("DrawSubTicks"=>TRUE, 'LabelRotation'=>25));
|
||
|
|
// $myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
|
||
|
|
// $myPicture->drawSplineChart();
|
||
|
|
// $LabelSettings = array("NoTitle"=>TRUE);
|
||
|
|
// $myPicture->writeLabel("My Serie 1",0, $LabelSettings);
|
||
|
|
// $myPicture->Render('charts/test.png');
|
||
|
|
|
||
|
|
// $pdf->loadHTML('<h1 id="test" style="color:red;">Test</h1><img src="charts/test.png" />');
|
||
|
|
// return $pdf->download();
|
||
|
|
return view('export.index')->with(['sites'=> $sites, 'startdate' => $startdate, 'enddate' => $enddate]);
|
||
|
|
}
|
||
|
|
|
||
|
|
//------ AJAX Export
|
||
|
|
public function export_coupons(Request $request){
|
||
|
|
$ids = $request->input('ids');
|
||
|
|
$startdate = date('Y-m-d', strtotime($request->input('startdate')));
|
||
|
|
$enddate = date('Y-m-d', strtotime($request->input('enddate')));
|
||
|
|
$coupons = Coupon::find($ids);
|
||
|
|
|
||
|
|
$labels = $this->getLabelsForStats($startdate, $enddate);
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
foreach ($coupons as $coupon) {
|
||
|
|
$cpName = str_replace(' ', '', $coupon->coupon_name);
|
||
|
|
$now = strtotime(now());
|
||
|
|
$full_path = 'export/'.$cpName.'_'.$now.'.pdf';
|
||
|
|
$dataCoupon = $this->getDataForCouponAllCamp($labels, $coupon);
|
||
|
|
$coupon->couponQuantity = $this->getFullQuantity($coupon);
|
||
|
|
$coupon->couponFullPrinted = $this->getUsedQuantity($coupon);
|
||
|
|
$coupon->couponPrinted = $this->getUsedQuantityOnPeriod($coupon, $startdate, $enddate);
|
||
|
|
|
||
|
|
$pdf = App::make('dompdf.wrapper');
|
||
|
|
|
||
|
|
$myData = new Data();
|
||
|
|
|
||
|
|
$myData->addPoints($dataCoupon,"My Serie 1");
|
||
|
|
$myData->addPoints($labels,"My Serie 2");
|
||
|
|
$myData->setAxisName(0,"Coupons Diffusés");
|
||
|
|
$myData->setAbscissa("My Serie 2");
|
||
|
|
$myData->setSerieTicks("My Serie 2",2);
|
||
|
|
$serieSettings = array("R"=>229,"G"=>11,"B"=>11);
|
||
|
|
$myData->setPalette("My Serie 1",$serieSettings);
|
||
|
|
$myPicture = new Image(700,230,$myData);
|
||
|
|
$myPicture->setGraphArea(60,40,670,190);
|
||
|
|
$myPicture->setFontProperties(array("FontSize"=>10));
|
||
|
|
$myPicture->drawScale(array("DrawSubTicks"=>TRUE, 'LabelSkip'=>1, 'LabelRotation'=>25, "Mode" => SCALE_MODE_START0, "CycleBackground"=>TRUE,"GridR"=>102,"GridG"=>102,"GridB"=>102));
|
||
|
|
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
|
||
|
|
$myPicture->drawLineChart(array("DisplayColor"=>DISPLAY_AUTO));
|
||
|
|
$LabelSettings = array("NoTitle"=>TRUE);
|
||
|
|
$myPicture->Render('export/temp.png');
|
||
|
|
|
||
|
|
$view = view('export.template')->with(['src' => 'export/temp.png', 'coupon' => $coupon, 'startdate' => $startdate, 'enddate' => $enddate])->render();
|
||
|
|
|
||
|
|
//var_dump($view);
|
||
|
|
|
||
|
|
$pdf->loadHTML($view);
|
||
|
|
$pdf->save($full_path);
|
||
|
|
}
|
||
|
|
|
||
|
|
return json_encode($full_path);
|
||
|
|
}
|
||
|
|
}
|