Skip to content

Commit

Permalink
Merge pull request #2 from eufelipemateus/dev
Browse files Browse the repository at this point in the history
Invoce Payment Feature
  • Loading branch information
eufelipemateus authored May 15, 2022
2 parents 21d533d + 0f4d67f commit d3417d7
Show file tree
Hide file tree
Showing 22 changed files with 737 additions and 47 deletions.
14 changes: 9 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "felipemateus/iptv-customers",
"version": "0.1.4",
"version": "0.2.0",
"description": "This package controls the IPTV Customers list and generates an m3u8 file for each customer using laravel.",
"type": "library",
"license": "MIT",
Expand Down Expand Up @@ -36,9 +36,10 @@
"require": {
"php": "^7.4|^8.0",
"laravel/framework": "8.82.0",
"felipemateus/iptv-core":"^1.0",
"felipemateus/iptv-channels": "^3.0.2",
"felipemateus/http-build-url": "^0.0.1"
"felipemateus/iptv-core":"^1.1",
"felipemateus/iptv-channels": "^3.0.3",
"felipemateus/http-build-url": "^0.0.1",
"felipemateus/laravel-iptv-gateway-payment":"^0.0.1"
},
"autoload": {
"psr-4": {
Expand All @@ -53,5 +54,8 @@
}
},
"minimum-stability": "stable",
"prefer-stable": true
"prefer-stable": true,
"suggest": {
"felipemateus/iptv-customers": "Allows you to control customers, plans assigned to each channel."
}
}
57 changes: 57 additions & 0 deletions src/Commands/GenerateInvoces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace FelipeMateus\IPTVCustomers\Commands;

use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Mail;
use FelipeMateus\IPTVCustomers\Models\IPTVCustomer;
use FelipeMateus\IPTVCustomers\Models\IPTVCustomerInvoce;

class GenerateInvoces extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'invoce:month';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate All invoces to current month.';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{

$this->info( sprintf('Generating invoices for the month %s.', date('m/Y')) );
$customers = IPTVCustomer::where("active",1)->get();

foreach($customers as $customer){
$format = sprintf('Y-m-%d', $customer->due_day);
$due_day_this_month = date($format);
IPTVCustomerInvoce::create(['duedate_at'=>$due_day_this_month,'iptv_customer_id'=> $customer->id]);
$message = sprintf('Generated invoce to %s with due date %s.', $customer->name, $due_day_this_month );
$this->warn($message);
}
$this->info('All Invoces generate successfully.');
}
}
46 changes: 29 additions & 17 deletions src/Controllers/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use FelipeMateus\IPTVCustomers\Models\IPTVCustomer;
use FelipeMateus\IPTVCore\Controllers\CoreController;
use FelipeMateus\IPTVChannels\Model\IPTVCdn;
use FelipeMateus\IPTVGatewayPayment\Models\IPTVGateway;

class CustomerController extends CoreController
{
Expand Down Expand Up @@ -35,8 +36,8 @@ public function new(){
/**
* Show page from customer with id.
*
* @param $id - channewl id
* @return view -> IPTV:chanel
* @param $id - customer id
* @return view -> IPTV::customer
*/
public function show($id){
$data["Customer"] = IPTVCustomer::findOrFail($id);
Expand All @@ -45,59 +46,70 @@ public function show($id){
$data['Cdnslist'] = IPTVCdn::all();
$data['CustomerPlansAddionalList'] = $data["Customer"]->plans_additional()->get();
$data['CustomerInvoceList'] = $data["Customer"]->customer_invoce()->get();
$data['GatewaysList'] = IPTVGateway::where('active',1)->get();

return view("IPTV::customer",$data);
}

/**
* Save new data from new channel in database.
* Save new data from new customer in database.
*
* @return redirect -> list_channels
* @return redirect -> show_costumer
*/
public function create(Request $request){
$this->validate($request, [
'name' => 'string|required',
'username' => 'required|string',
'iptv_plan_id' => 'required|exists:iptv_plans,id',
'industry'=>'string|nullable',
'address'=>'string|nullable',
'phone'=>'string|nullable',
'email'=>'string|nullable',
'tax_no'=>'string|nullable',
]);
$data = $request->all();
$data['hash_acess'] = md5(now());
IPTVCustomer::create($data);
return redirect()->route('list_customer');
$customer = IPTVCustomer::create($data);
return redirect()->route('show_customer',['id'=>$customer->id]);
}

/**
* Save new data from new channel in database.
* Update customer in database.
*
* @param id from channel
* @return redirect -> list_channels
* @param id from customer
* @return redirect -> list_customers
*/
public function update($id,Request $request){
$channel =IPTVCustomer::findOrFail($id);
$customer =IPTVCustomer::findOrFail($id);

$this->validate($request, [
'name' => 'string|required',
'username' => 'required|string',
'iptv_plan_id' => 'required|exists:iptv_plans,id',
'industry'=>'string|nullable',
'address'=>'string|nullable',
'phone'=>'string|nullable',
'email'=>'string|nullable',
'tax_no'=>'string|nullable',
'active'=>'boolean',
]);

$data = $request->all();

$data['active'] = $request->boolean('active','bool');
$channel->update($data);
$customer->update($data);

return redirect()->route('list_customer');
return redirect()->route('show_customer',['id'=>$customer->id]);
}

/**
* Delete channel form database.
* Delete customer form database.
*
* @param id from channel
* @param id from customer
* @return redirect -> list_customer
*/
public function delete($id,Request $request){
$group =IPTVCustomer::findOrFail($id);
$group->delete();
$customer =IPTVCustomer::findOrFail($id);
$customer->delete();
return redirect()->route('list_customer');
}

Expand Down
75 changes: 68 additions & 7 deletions src/Controllers/InvoceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
use Illuminate\Http\Request;
use FelipeMateus\IPTVCore\Controllers\CoreController;
use FelipeMateus\IPTVCustomers\Models\IPTVCustomerInvoce;
use FelipeMateus\IPTVCustomers\Models\IPTVCustomer;
use FelipeMateus\IPTVCustomers\Requests\IPTVCustomerInvoceCreateInvoceRequest;
use FelipeMateus\IPTVGatewayPayment\Models\IPTVGateway;
use FelipeMateus\IPTVCore\Model\IPTVConfig;

use DateTime;

class InvoceController extends CoreController
Expand All @@ -29,16 +33,73 @@ public function create($customer_id, IPTVCustomerInvoceCreateInvoceRequest $requ
}

public function pay($customer_id, $id){
$customer = IPTVCustomerInvoce::find($id);
$customer->payment_at = now();
$customer->save();
return redirect()->route('show_customer', ['id'=>$customer_id]);
$data['invoce'] = IPTVCustomerInvoce::find($id);
$data['GatewaysList'] = IPTVGateway::where('active', true)->get();
$data['ConfigData'] = IPTVConfig::getAllStringSettings();

$data['subtotal'] = 0;
$data['totalDiscount'] = 0;
$data['total'] = 0 ;
$data['totalTax'] = 0;
$data['final'] = 0;

$customer = IPTVCustomer::find($customer_id);
$index = 0;
$services[$index ]['service'] = $customer->plan->name;
$services[$index ]['service_type'] = 'Principal';
$services[$index ]['price'] = $customer->plan->price;
$services[$index ]['discont'] = 0;
$services[$index ]['tax'] = ($services[$index ]['price'] - $services[$index ]['discont']) * ( ((isset($customer->plan->tax_vat->porcent))? $customer->plan->tax_vat->porcent : 0) / 100) ;
$services[$index ]['tax_porcent'] = (isset($customer->plan->tax_vat->porcent))? $customer->plan->tax_vat->porcent : 0;
$services[$index ]['total'] = $services[$index ]['price'] + $services[$index ]['tax'];
$services[$index ]['subtotal'] = $services[$index ]['price'] - $services[$index ]['discont'];
$index++;

foreach($customer->plans_additional as $plan){
$services[$index ]['service'] = $plan->name;
$services[$index ]['service_type'] = 'Additional';
$services[$index ]['price'] = $plan->price;
$services[$index ]['discont'] = 0;
$services[$index ]['tax'] = ($services[$index ]['price'] - $services[$index ]['discont']) * ( ((isset($plan->tax_vat->porcent))? $plan->tax_vat->porcent : 0) / 100) ;
$services[$index ]['tax_porcent'] = (isset($plan->tax_vat->porcent) && $plan->tax_vat->porcent != null)? $plan->tax_vat->porcent : 0;
$services[$index ]['total'] = $services[$index ]['price'] + $services[$index ]['tax'];
$services[$index ]['subtotal'] = $services[$index ]['price'] - $services[$index ]['discont'];
$index ++;
}

$data['services'] = $services;
// Total
foreach($services as $service){
$data['subtotal'] += $service['price'];
}

// Total Discount
foreach($services as $service){
$data['totalDiscount'] += $service['discont'];
}

// Total = Total - Discount
foreach($services as $service){
$data['total'] += $service['price'] - $service['discont'];
}

// Total tax
foreach($services as $service){
$data['totalTax'] += $service['tax'];
}

// Final
foreach($services as $service){
$data['final'] = $data['totalTax'] + $data['total'];
}

return view("IPTV::invoce", $data);
}

public function cancel($customer_id, $id){
$customer = IPTVCustomerInvoce::find($id);
$customer->canceled_at = now();
$customer->save();
$invoce = IPTVCustomerInvoce::find($id);
$invoce->canceled_at = now();
$invoce->save();
return redirect()->route('show_customer', ['id'=>$customer_id]);
}
}
21 changes: 18 additions & 3 deletions src/Controllers/PlanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

use Illuminate\Http\Request;
use FelipeMateus\IPTVCustomers\Models\IPTVPlan;
use FelipeMateus\IPTVChannels\Model\IPTVChannelGroup;
use FelipeMateus\IPTVChannels\Model\IPTVChannelGroup;
use FelipeMateus\IPTVCore\Controllers\CoreController;
use FelipeMateus\IPTVGatewayPayment\Models\IPTVTaxVat;

class PlanController extends CoreController
{
Expand All @@ -25,7 +26,8 @@ public function __construct()
* @return view -> IPTV::plan
*/
public function new(){
return view("IPTV::plan");
$data['TaxVatList'] = IPTVTaxVat::where('active', true)->get();
return view("IPTV::plan", $data);
}

/**
Expand All @@ -35,6 +37,8 @@ public function new(){
*/
public function create(Request $request){
$data = $request->all();
$data = $request->except(['iptv_tax_vat_id']);
$tax_vat = $request->only('iptv_tax_vat_id')['iptv_tax_vat_id'];
IPTVPlan::create($data);
return redirect()->route('list_plan');
}
Expand All @@ -49,6 +53,7 @@ public function show($id){
$data["Plan"] = IPTVPlan::findOrFail($id);
$data['GroupList'] = $data["Plan"]->groupsList();
$data['PlanGroupList'] =$data["Plan"]->groups;
$data['TaxVatList'] = IPTVTaxVat::where('active', true)->get();
return view("IPTV::plan",$data);
}

Expand All @@ -60,7 +65,9 @@ public function show($id){
*/
public function update($id,Request $request){
$plan =IPTVPlan::findOrFail($id);
$data = $request->all();
$data = $request->except(['iptv_tax_vat_id']);
$tax_vat = $request->only('iptv_tax_vat_id')['iptv_tax_vat_id'];

$plan->update($data);

if(!isset($data['active'])){
Expand All @@ -75,6 +82,14 @@ public function update($id,Request $request){
$plan->additional=true;
}

if(isset($tax_vat) ){
$plan->iptv_tax_vat_id= ($tax_vat == 'null')?
null
:
$tax_vat
;
}

$plan->save();
return redirect()->route('list_plan');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Dashs/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FelipeMateus\IPTVCustomers\Dashs;

use FelipeMateus\IPTVCore\Class\IPTVDashBase;
use FelipeMateus\IPTVCore\Helpers\IPTVDashBase;
use FelipeMateus\IPTVCustomers\Models\IPTVCustomer;

class Customers extends IPTVDashBase {
Expand Down
2 changes: 1 addition & 1 deletion src/Dashs/Plans.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace FelipeMateus\IPTVCustomers\Dashs;

use FelipeMateus\IPTVCore\Class\IPTVDashBase;
use FelipeMateus\IPTVCore\Helpers\IPTVDashBase;
use FelipeMateus\IPTVCustomers\Models\IPTVPlan;

class Plans extends IPTVDashBase {
Expand Down
Loading

0 comments on commit d3417d7

Please sign in to comment.