| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use Livewire\WithPagination;
- use Barryvdh\DomPDF\Facade\Pdf;
- class RecordIN extends Component
- {
- use WithPagination;
- protected $paginationTheme = 'bootstrap';
- protected $listeners = ['setCausal' => 'setCausal'];
- public $sortField ='date';
- public $sortAsc = false;
- public $typeIN = "IN";
- public $isDuplicate = false;
- public $multiP = false;
- public $multiMonthTo = 0;
- public $multiYearTo = 0;
- public $multiMonthFrom = 0;
- public $multiYearFrom = 0;
- public function sortBy($field)
- {
- if($this->sortField === $field)
- {
- $this->sortAsc = ! $this->sortAsc;
- } else {
- $this->sortAsc = true;
- }
- $this->sortField = $field;
- }
- public $records, $dataId, $member_id, $supplier_id,
- $causal_id,
- $payment_method_id,
- $date,
- $month,
- $year,
- $type,
- $amount,
- $vat,
- $virtual,
- $note,
- $commercial, $update = false, $add = false;
- public $currentReceip;
- public $filterMember = 0, $filterPaymentMethod = 0, $filterCausals = [], $filterFrom = '', $filterTo = '', $filterCommercial = 0;
- public $hasFilter = false;
- public $total = 0;
- public $selectedFilter = '';
- public $multipleIds = [];
- public $multipleAction = '';
- public $first = true;
- public $selectId = 0;
- public $refreshAfter = 0;
- public $canSave = true;
- public $newMemberFirstName = '';
- public $newMemberLastName = '';
- public $newMemberFiscalCode = '';
- public $newMemberFiscalCodeExist = false;
- public $causals = array();
- public $payments = array();
- public $members = array();
- public $vats = array();
- public $rows = array();
- protected $rules = [
- 'member_id' => 'required',
- 'payment_method_id' => 'required',
- 'rows.*.causal_id' => 'required',
- 'rows.*.amount' => 'required'
- ];
- protected $messages = [
- 'member_id.required' => 'La persona è obbligatorio',
- 'payment_method_id.required' => 'Il metodo di pagamento è obbligatorio',
- 'causal_id.required' => 'La causale è obbligatoria',
- 'amount.required' => 'L\'importo è obbligatorio',
- ];
- public function updatedMemberId() {
- $this->emit('refresh');
- if ($this->member_id > 0)
- {
- $member = \App\Models\Member::findOrFail($this->member_id);
- $this->virtual = $member->getMoney();
- $this->newMemberFirstName = '';
- $this->newMemberLastName = '';
- $this->newMemberFiscalCode = '';
- $this->newMemberFiscalCodeExist = false;
- }
- }
- public function updatedCausalId() {
- //$this->emit('refresh');
- }
- public function updatedDate() {
- //$this->emit('refresh');
- }
- public function hydrate()
- {
- $this->emit('load-select');
- }
- /*public function updated() {
- $this->emit('refresh');
- }*/
- public function updatedPaymentMethodId() {
- //$this->emit('refresh');
- $this->canSave = $this->checkCanSave();
- }
- public function updatedAmount() {
- // $this->emit('refresh');
- $this->canSave = $this->checkCanSave();
- }
- public function checkCanSave()
- {
- $ret = true;
- if ($this->payment_method_id != null)
- {
- $payment_method = \App\Models\PaymentMethod::findOrFail($this->payment_method_id);
- if ($payment_method->money)
- {
- $ret = $this->virtual >= $this->currencyToDouble($this->amount);
- }
- }
- return $ret;
- }
- public function resetFields(){
- $this->member_id = null;
- $this->supplier_id = null;
- $this->payment_method_id = null;
- $this->date = date("Y-m-d");
- $this->type = 'IN';
- $this->newMemberFirstName = '';
- $this->newMemberLastName = '';
- $this->newMemberFiscalCode = '';
- $this->newMemberFiscalCodeExist = false;
- $this->currentReceip = null;
- $this->rows = array();
- $this->rows[] = array('causal_id' => isset($_GET["causalId"]) ? $_GET["causalId"] : null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')), 'amount' => null, 'vat_id' => null, 'note' => '', 'commercial' => 0);
- }
- public function getMemberProperty()
- {
- $ret = null;
- if ($this->member_id > 0)
- {
- $ret = \App\Models\Member::findOrFail($this->member_id);
- }
- return $ret;
- }
- public function getCausalProperty()
- {
- $ret = null;
- if ($this->causal_id > 0)
- {
- $ret = \App\Models\Causal::findOrFail($this->causal_id);
- }
- return $ret;
- }
- public function getCausal($causal)
- {
- $ret = '';
- if ($causal > 0)
- {
- $ret = \App\Models\Causal::findOrFail($causal)->getTree();
- }
- return $ret;
- }
- function buildTree($records, $parentId = 0) {
- $this->causals = array();
- foreach ($records as $record)
- {
- if ($record->parent_id == $parentId)
- {
- $children = $this->buildTree($record, $record->id);
- if ($children) {
- $record->children = $children;
- }
- $this->causals[] = $record;
- }
- }
- return $this->causals;
- }
- public function getCausale($records, $indentation)
- {
- foreach($records as $record)
- {
- $this->causals[] = array('id' => $record->id, 'name' => $record->getTree(), 'text' => $record->getTree(), 'level' => $indentation);
- if(count($record->childs))
- $this->getCausale($record->childs, $indentation + 1);
- }
- }
- public function mount()
- {
- $this->causals = array();
- $this->multiMonthFrom = date("n");
- $this->multiYearFrom = date("Y");
- $this->multiMonthTo = date("n");
- $this->multiYearTo = date("Y");
- $this->getCausale(\App\Models\Causal::select('id', 'name')->where('parent_id', null)->where('type', 'IN')->get(), 0);
- //$this->buildTree(\App\Models\Causal::all(), null);
- $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])->orderBy('last_name')->orderBy('first_name')->get();
- $this->payments = \App\Models\PaymentMethod::select('id', 'name')->orderBy('name')->get();
- $this->vats = \App\Models\Vat::select('id', 'name', 'value')->orderBy('value')->get();
- if ($this->first)
- {
- if (isset($_GET["new"]))
- {
- $this->refreshAfter = 1;
- $this->add();
- }
- if (isset($_GET["memberId"]))
- {
- $this->refreshAfter = 1;
- $this->member_id = $_GET["memberId"];
- }
- if (isset($_GET["causalId"]))
- {
- $this->refreshAfter = 1;
- $this->causal_id = $_GET["causalId"];
- }
- if (isset($_GET["id"]))
- {
- $this->refreshAfter = 1;
- $this->edit($_GET["id"]);
- }
- }
- $this->first = false;
- }
- public function search()
- {
- $this->hasFilter = true;
- }
- public function disableSearch()
- {
- $this->filterMember = 0;
- $this->filterPaymentMethod = 0;
- $this->filterCausals = [];
- $this->filterTo = '';
- $this->filterFrom = '';
- $this->filterCommercial = 0;
- $this->hasFilter = false;
- $this->total = 0;
- }
- public function render()
- {
- $datas = [];
- if ($this->hasFilter)
- {
- $datas = \App\Models\Record::select('records.*', \DB::raw('members.first_name as first_name'), \DB::raw('members.last_name as last_name'), \DB::raw('payment_methods.name as payment')) // , \DB::raw('SUM(records.id) As total'))
- ->leftJoin('members', 'records.member_id', '=', 'members.id')
- ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
- ->where('records.type', 'IN');
- // $datas = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method');
- /*if ($this->filterCommercial > 0)
- {
- $datas = $datas->where('commercial', $this->filterCommercial == 1 ? true : false);
- }*/
- if ($this->filterMember > 0)
- {
- $datas = $datas->where('member_id', $this->filterMember);
- }
- if ($this->filterPaymentMethod > 0)
- {
- $datas = $datas->where('payment_method_id', $this->filterPaymentMethod);
- }
- /*if (sizeof($this->filterCausals) > 0)
- {
- $datas = $datas->whereIn('causal_id', $this->filterCausals);
- }*/
- if ($this->filterFrom != '')
- {
- $datas = $datas->where('date', '>=', $this->filterFrom);
- }
- if ($this->filterTo != '')
- {
- $datas = $datas->where('date', '<=', $this->filterTo);
- }
- // $this->records = $datas->orderBy('date', 'DESC')->get();
- //$this->records = $datas->get();
- $this->total = 0;
- foreach($datas->get() as $r)
- {
- foreach($r->rows as $rr)
- {
- $this->total += $rr->amount;
- if ($rr->vat_id > 0)
- $this->total += getVatValue($rr->amount, $rr->vat_id);
- }
- }
- $datas = $datas->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')->paginate(20);
- //$this->total = $this->records->sum('amount');
- }
- else
- {
- if ($this->selectedFilter == '')
- {
- // $this->records = \App\Models\Record::where('type', 'IN')->with('member', 'payment_method')->limit(20)->orderBy('date', 'DESC')->orderBy('id', 'DESC')->get();
- $datas = \App\Models\Record::select('records.*', \DB::raw('members.first_name as first_name'), \DB::raw('members.last_name as last_name'), \DB::raw('payment_methods.name as payment')) // , \DB::raw('SUM(records.id) As total'))
- ->leftJoin('members', 'records.member_id', '=', 'members.id')
- ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
- ->where('records.type', 'IN')
- ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')
- ->paginate(20);
- }
- else
- {
- if ($this->selectedFilter == 0)
- {
- $fromDate = date("Y-m-d");
- $toDate = date("Y-m-d");
- }
- if ($this->selectedFilter == 1)
- {
- $fromDate = date("Y-m-01");
- $toDate = date("Y-m-t");
- }
- if ($this->selectedFilter == 2)
- {
- $fromDate = date("Y-01-01");
- $toDate = date("Y-12-31");
- }
- if ($this->selectedFilter == 3)
- {
- $fromDate = date("2000-01-01");
- $toDate = date("Y-12-31");
- }
- /*
- $this->records = \App\Models\Record::where('type', 'IN')->whereBetween('date', [$fromDate, $toDate])->with('member', 'payment_method')->get();
- $datas = \App\Models\Record::select('records.*', \DB::raw('members.first_name as first_name'), \DB::raw('members.last_name as last_name'), \DB::raw('payment_methods.name as payment'), \DB::raw('SUM(records.id) As total'))
- ->leftJoin('members', 'records.member_id', '=', 'members.id')
- ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
- //->where('analytics.date', Carbon::today()->toDateString())
- ->paginate(1);*/
- $datas = \App\Models\Record::select('records.*', \DB::raw('members.first_name as first_name'), \DB::raw('members.last_name as last_name'), \DB::raw('payment_methods.name as payment')) // , \DB::raw('SUM(records.id) As total'))
- ->leftJoin('members', 'records.member_id', '=', 'members.id')
- ->leftJoin('payment_methods', 'records.payment_method_id', '=', 'payment_methods.id')
- ->where('records.type', 'IN')
- ->whereBetween('date', [$fromDate, $toDate])
- ->orderBy($this->sortField, $this->sortAsc ? 'ASC' : 'DESC')
- ->paginate(20);
- }
- }
- /*
- foreach($this->records as $r)
- {
- $r->total = $r->getTotal();
- $r->person = $r->member ? ($r->member->first_name . " " . $r->member->last_name) : '';
- $r->payment = $r->payment_method ? $r->payment_method->name : '';
- }
- if ($this->sortField != '')
- {
- if ($this->sortAsc)
- $this->records = $this->records->sortBy($this->sortField);
- else
- $this->records = $this->records->sortByDesc($this->sortField);
- }
- else
- $this->records = $this->records->sortByDesc('id');
- */
- return view('livewire.records_in', ['datas' => $datas]);
- }
- public function executeMultipleAction(){
- if ($this->multipleAction == 'delete')
- $this->multipleDelete();
- }
- public function add()
- {
- $this->emit('load-select');
- //if ($this->hasFilter)
- $this->emit('hide-search');
- $this->resetFields();
- $this->add = true;
- $this->update = false;
- }
- public function store($generate)
- {
- $this->emit('refresh');
- $rules = [
- 'payment_method_id' => 'required',
- 'rows.*.causal_id' => 'required',
- 'rows.*.amount' => 'required'
- ];
- $f = false;
- foreach($this->rows as $row)
- {
- if ($row["commercial"]) $f = true;
- }
- if ($f)
- $rules["member_id"] = 'required';
- $this->validate($rules);
- try {
- $record = \App\Models\Record::create([
- 'member_id' => $this->member_id,
- 'supplier_id' => $this->supplier_id,
- 'payment_method_id' => $this->payment_method_id,
- 'date' => $this->date,
- 'type' => $this->type,
- ]);
- $this->dataId = $record->id;
- // Inserisco le righe
- $tot = 0;
- $vat = 0;
- foreach($this->rows as $row)
- {
- foreach($row["when"] as $x => $y)
- {
- $row["when"][$x]['period'] = $row["when"][$x]['month'] . "-" . $row["when"][$x]['year'];
- }
- \App\Models\RecordRow::create([
- 'record_id' => $this->dataId,
- 'causal_id' => $row["causal_id"],
- 'note' => $row["note"],
- 'amount' => $this->currencyToDouble($row["amount"]),
- 'vat_id' => $row["vat_id"],
- 'commercial' => $row["commercial"],
- 'when' => json_encode($row["when"])
- ]);
- $tot += $this->currencyToDouble($row["amount"]);
- $vat += getVatValue($this->currencyToDouble($row["amount"]), $row["vat_id"]);
- }
- $record->amount = $tot;
- $record->save();
- if ($generate)
- $this->createReceipt();
- session()->flash('success','Movimento creato');
- $this->resetFields();
- $this->add = false;
- $this->isDuplicate = false;
- } catch (\Exception $ex) {
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
- }
- }
- public function duplicate($id){
- $record = \App\Models\Record::findOrFail($id);
- $newRecord = $record->replicate();
- $newRecord->save();
- $rows = \App\Models\RecordRow::where('record_id', $id)->get();
- foreach($rows as $r)
- {
- $newRow = $r->replicate();
- $newRow->record_id = $newRecord->id;
- $newRow->save();
- }
- $this->isDuplicate = true;
- $this->edit($newRecord->id);
- }
- public function edit($id){
- //if ($this->hasFilter)
- $this->emit('hide-search');
- $this->emit('load-select');
- try {
- $record = \App\Models\Record::findOrFail($id);
- if( !$record) {
- session()->flash('error','Movimento non trovato');
- } else {
- $this->member_id = $record->member_id;
- $this->supplier_id = $record->supplier_id;
- $this->payment_method_id = $record->payment_method_id;
- $this->date = date("Y-m-d", strtotime($record->date));
- $this->type = $record->type;
- $this->dataId = $record->id;
- $this->update = true;
- $this->add = false;
- $this->rows = \App\Models\RecordRow::where('record_id', $this->dataId)->select('causal_id', 'note', 'commercial', 'when', 'amount', 'vat_id')->get()->toArray();
- foreach($this->rows as $i => $r)
- {
- $this->rows[$i]['amount'] = formatPrice($this->rows[$i]['amount']);
- $this->rows[$i]['vat_id'] = $this->rows[$i]['vat_id'];
- $this->rows[$i]['when'] = json_decode($this->rows[$i]['when']);
- }
- $exist = \App\Models\Receipt::where('record_id', $id)->orderBy('id', 'DESC')->first();
- if ($exist != null)
- $this->currentReceip = $exist;
- }
- } catch (\Exception $ex) {
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
- }
- }
- public function update($generate)
- {
- $this->emit('refresh');
- $rules = [
- 'payment_method_id' => 'required',
- 'rows.*.causal_id' => 'required',
- 'rows.*.amount' => 'required'
- ];
- $f = false;
- foreach($this->rows as $row)
- {
- if ($row["commercial"]) $f = true;
- }
- if ($f)
- $rules["member_id"] = 'required';
- $this->validate($rules);
- try {
- \App\Models\Record::whereId($this->dataId)->update([
- 'member_id' => $this->member_id,
- 'supplier_id' => $this->supplier_id,
- 'payment_method_id' => $this->payment_method_id,
- 'date' => date("Y-m-d", strtotime($this->date)),
- 'type' => $this->type,
- ]);
- $tot = 0;
- $vat = 0;
- // Elimino le righe
- \App\Models\RecordRow::where('record_id', $this->dataId)->delete();
- // Inserisco le righe
- foreach($this->rows as $row)
- {
- foreach($row["when"] as $x => $y)
- {
- $row["when"][$x]['period'] = $row["when"][$x]['month'] . "-" . $row["when"][$x]['year'];
- }
- \App\Models\RecordRow::create([
- 'record_id' => $this->dataId,
- 'causal_id' => $row["causal_id"],
- 'note' => $row["note"],
- 'vat_id' => $row["vat_id"],
- 'amount' => $this->currencyToDouble($row["amount"]),
- 'commercial' => $row["commercial"],
- 'when' => json_encode($row["when"])
- ]);
- $tot += $this->currencyToDouble($row["amount"]);
- $vat += getVatValue($this->currencyToDouble($row["amount"]), $row["vat_id"]);
- }
- $rec = \App\Models\Record::findOrFail($this->dataId);
- $rec->amount = $tot;
- $rec->save();
- if ($generate)
- $this->createReceipt();
- session()->flash('success','Movimento aggiornato');
- $this->resetFields();
- $this->update = false;
- $this->isDuplicate = false;
- } catch (\Exception $ex) {
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
- }
- }
- public function cancel()
- {
- // Se arrivo da duplica elimino
- if ($this->isDuplicate)
- {
- try{
- \App\Models\Record::find($this->dataId)->delete();
- session()->flash('success',"Movimento eliminato");
- }catch(\Exception $e){
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
- }
- }
- $this->isDuplicate = false;
- $this->add = false;
- $this->update = false;
- $this->resetFields();
- }
- public function delete($id)
- {
- try{
- \App\Models\Record::find($id)->delete();
- session()->flash('success',"Movimento eliminato");
- }catch(\Exception $e){
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
- }
- }
- public function multipleDelete()
- {
- try{
- foreach($this->multipleIds as $id)
- {
- \App\Models\Record::find($id)->delete();
- }
- }catch(\Exception $e){
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
- }
- $this->multipleAction = '';
- }
- public function createMember()
- {
- $this->newMemberFiscalCodeExist = false;
- $this->validate([
- // 'newMemberFiscalCode'=>'required|max:16',
- 'newMemberFirstName'=>'required',
- 'newMemberLastName'=>'required'
- ]);
- // Check fiscal code exist
- $exist = false;
- if ($this->newMemberFiscalCode != '')
- {
- $check = \App\Models\Member::where('fiscal_code', $this->newMemberFiscalCode)->get();
- $exist = $check->count() > 0;
- }
- if (!$exist)
- {
- $member = \App\Models\Member::create([
- 'first_name' => $this->newMemberFirstName,
- 'last_name' => $this->newMemberLastName,
- 'fiscal_code' => $this->newMemberFiscalCode,
- 'status' => true
- ]);
- $this->member_id = $member->id;
- $this->members = \App\Models\Member::select(['id', 'first_name', 'last_name', 'fiscal_code'])->get();
- // $this->emit('reloadMembers');
- $this->emit('refresh');
- $this->newMemberFirstName = '';
- $this->newMemberLastName = '';
- $this->newMemberFiscalCode = '';
- $this->emit('saved');
- //$this->validate();
- $this->selectId++;
- }
- else
- {
- $this->newMemberFiscalCodeExist = true;
- }
- }
- public function createReceipt()
- {
- $create = false;
- $receipt = \App\Models\Receipt::where('record_id', $this->dataId)->orderBy('id', 'DESC')->first();
- if ($receipt != null)
- {
- // Controllo lo stato, se 99 ne genero una nuova
- if ($receipt->status == 99)
- {
- $create = true;
- }
- }
- else
- {
- $create = true;
- }
- if ($create)
- {
- $number = 1;
- $exist = \App\Models\Receipt::where('year', date("Y"))->orderBy('number', 'DESC')->first();
- if ($exist != null)
- $number = $exist->number + 1;
- $receipt = \App\Models\Receipt::create([
- 'record_id' => $this->dataId,
- 'member_id' => $this->member_id,
- 'supplier_id' => $this->supplier_id,
- 'payment_method_id' => $this->payment_method_id,
- 'number' => $number,
- 'date' => $this->date,
- 'year' => date("Y"),
- 'type' => $this->type,
- 'status' => 1,
- ]);
- foreach($this->rows as $row)
- {
- \App\Models\ReceiptRow::create([
- 'receip_id' => $receipt->id,
- 'causal_id' => $row["causal_id"],
- 'note' => $row["note"],
- 'vat_id' => $row["vat_id"],
- 'amount' => $this->currencyToDouble($row["amount"]),
- 'commercial' => $row["commercial"],
- 'when' => json_encode($row["when"])
- ]);
- }
- $this->currentReceip = $receipt;
- }
- }
- public function removeReceipt()
- {
- $receipt = \App\Models\Receipt::findOrFail($this->currentReceip->id);
- $receipt->status = 99;
- $receipt->save();
- $this->currentReceip = $receipt;
- }
- function currencyToDouble($val)
- {
- $x = str_replace("€", "", $val);
- $x = str_replace(".", "", $x);
- $x = str_replace(",", ".", $x);
- return trim($x);
- }
- public function addRow()
- {
- $this->rows[] = array('causal_id' => null, 'when' => array(array('month' => date("n"), 'year' => date("Y"), 'period' => '')), 'amount' => null, 'vat_id' => null, 'note' => '', 'commercial' => 0);
- $this->emit('load-select');
- }
- public function delRow($idx)
- {
- unset($this->rows[$idx]);
- // $this->emit('load-select');
- }
- public function addPeriod($idx)
- {
- $x = sizeof($this->rows[$idx]['when']) - 1;
- $newDate = \Carbon\Carbon::create($this->rows[$idx]['when'][$x]["year"] . "-" . $this->rows[$idx]['when'][$x]["month"] . '-01')->addMonth();
- $this->rows[$idx]['when'][] = array('month' => $newDate->format("n"), 'year' => $newDate->format("Y"), 'period' => '');
- }
- public function delPeriod($idx, $xxx)
- {
- unset($this->rows[$idx]['when'][$xxx]);
- // $this->emit('load-select');
- }
- public function getTotal()
- {
- $total = 0.00;
- foreach($this->rows as $r)
- {
- if ($r["amount"] != null && $r["amount"] != "")
- {
- $total += $this->currencyToDouble($r["amount"]);
- if ($r["vat_id"] > 0)
- $total += getVatValue($this->currencyToDouble($r["amount"]), $r["vat_id"]);
- }
- }
- return formatPrice($total);
- // $this->emit('load-select');
- }
- public function getPrice()
- {
- $total = 0.00;
- foreach($this->rows as $r)
- {
- if ($r["amount"] != null && $r["amount"] != "")
- $total += $this->currencyToDouble($r["amount"]);
- }
- return formatPrice($total);
- // $this->emit('load-select');
- }
- public function getVat()
- {
- $total = 0.00;
- foreach($this->rows as $r)
- {
- if ($r["amount"] != null && $r["amount"] != "" && $r["vat_id"] > 0)
- $total += getVatValue($this->currencyToDouble($r["amount"]), $r["vat_id"]);
- }
- return formatPrice($total);
- // $this->emit('load-select');
- }
- public function setCausal($id, $idx)
- {
- $this->rows[$idx]["causal_id"] = $id;
- }
- public function printReceipt()
- {
- //$pdf = PDF::loadView('pdf/receipt', array('datas' => $datas, 'from' => $x, 'to' => $y, 'who' => '', 'matricola' => $matricola));
- $pdf = PDF::loadView('receipt', array('receipt' => $this->currentReceip))->output();
- return response()->streamDownload(
- fn () => print($pdf),
- "ricevuta_" . $this->currentReceip->number . "_" . $this->currentReceip->year . ".pdf"
- );
- /*return response()->streamDownload(function () {
- echo $pdf->stream();
- }, 'test.pdf');*/
- }
- public function multiPeriod()
- {
- $this->multiP = true;
- }
- public function multiPeriodCreate($idx)
- {
- $period = \Carbon\CarbonPeriod::create($this->multiYearFrom . '-' . $this->multiMonthFrom . '-01', '1 month', $this->multiYearTo . '-' . $this->multiMonthTo . '-01');
- foreach ($period as $dt) {
- if (!in_array(array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => ''), $this->rows[$idx]['when']))
- $this->rows[$idx]['when'][] = array('month' => $dt->format("n"), 'year' => $dt->format("Y"), 'period' => '');
- }
- $this->multiP = false;
- }
- }
|