diff --git a/app/Http/CompanyGatewayController.php b/app/Http/CompanyGatewayController.php new file mode 100644 index 000000000000..9acd5bf9d9d8 --- /dev/null +++ b/app/Http/CompanyGatewayController.php @@ -0,0 +1,195 @@ +company_repo = $company_repo; + + } + + /** + * Display a listing of the resource. + * + * @return \Illuminate\Http\Response + */ + public function index() + { + $company_gateways = CompanyGateway::whereCompanyId(auth()->user()->company()->id); + + return $this->listResponse($company_gateways); + + } + + /** + * Show the form for creating a new resource. + * + * @return \Illuminate\Http\Response + */ + public function create(CreateCompanyRequest $request) + { + + $company = CompanyFactory::create(auth()->user()->company()->account->id); + + return $this->itemResponse($company); + } + + /** + * Store a newly created resource in storage. + * + * @param \App\Http\Requests\SignupRequest $request + * @return \Illuminate\Http\Response + */ + public function store(StoreCompanyRequest $request) + { + $this->forced_includes = ['company_user']; + + $company = CreateCompany::dispatchNow($request->all(), auth()->user()->company()->account); + + if($request->file('logo')) + { + \Log::error('logo exists'); + $path = UploadAvatar::dispatchNow($request->file('logo'), $company->company_key); + + if($path){ + $company->logo = $path; + $company->save(); + } + + } + + auth()->user()->companies()->attach($company->id, [ + 'account_id' => $company->account->id, + 'is_owner' => 1, + 'is_admin' => 1, + 'is_locked' => 0, + 'permissions' => json_encode([]), + 'settings' => json_encode(DefaultSettings::userSettings()), + ]); + + /* + * Required dependencies + */ + auth()->user()->setCompany($company); + + /* + * Create token + */ + $company_token = CreateCompanyToken::dispatchNow($company, auth()->user()); + + //todo Need to discuss this with Hillel which is the best representation to return + //when a company is created. Do we send the entire account? Do we only send back the created CompanyUser? + $this->entity_transformer = CompanyUserTransformer::class; + $this->entity_type = CompanyUser::class; + + //return $this->itemResponse($company); + $ct = CompanyUser::whereUserId(auth()->user()->id); + + return $this->listResponse($ct); + + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show(ShowCompanyRequest $request, Company $company) + { + + return $this->itemResponse($company); + + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit(EditCompanyRequest $request, Company $company) + { + + return $this->itemResponse($company); + + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(UpdateCompanyRequest $request, Company $company) + { + $company = $this->company_repo->save($request->all(), $company); + + if($request->file('logo')) + { + \Log::error('logo exists'); + $path = UploadAvatar::dispatchNow($request->file('logo'), $company->company_key); + + if($path){ + $company->logo = $path; + $company->save(); + } + + } + + return $this->itemResponse($company); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy(DestroyCompanyRequest $request, Company $company) + { + + $company->delete(); + + return response()->json([], 200); + } +} diff --git a/app/Listeners/Invoice/UpdateInvoicePayment.php b/app/Listeners/Invoice/UpdateInvoicePayment.php index 7bfcb37a7ab1..9f0ea3a7ecca 100644 --- a/app/Listeners/Invoice/UpdateInvoicePayment.php +++ b/app/Listeners/Invoice/UpdateInvoicePayment.php @@ -63,7 +63,7 @@ class UpdateInvoicePayment implements ShouldQueue foreach($invoice as $invoice) { - if($invoice->isPartial()) + if($invoice->hasPartial()) $total += $invoice->partial; else $total += $invoice->balance; @@ -77,7 +77,7 @@ class UpdateInvoicePayment implements ShouldQueue $invoices->each(function ($invoice) use($payment){ - if($invoice->isPartial()) { + if($invoice->hasPartial()) { UpdateCompanyLedgerWithPayment::dispatchNow($payment, ($invoice->partial*-1)); $invoice->updateBalance($invoice->partial*-1); diff --git a/app/Models/CompanyGateway.php b/app/Models/CompanyGateway.php index a0da1e9867c7..d10513e36dae 100644 --- a/app/Models/CompanyGateway.php +++ b/app/Models/CompanyGateway.php @@ -22,8 +22,26 @@ class CompanyGateway extends BaseModel { protected $fillable = [ + 'gateway_key', + 'accepted_credit_cards', + 'require_cvv', + 'show_address', + 'show_shipping_address', + 'update_details', + 'config', + 'priority_id', + 'min_limit', + 'max_limit', + 'fee_amount', + 'fee_percent', + 'fee_tax_name1', + 'fee_tax_name2', + 'fee_tax_rate1', + 'fee_tax_rate2', + 'fee_cap', + 'adjust_fee_percent', ]; - + public static $credit_cards = [ 1 => ['card' => 'images/credit_cards/Test-Visa-Icon.png', 'text' => 'Visa'], 2 => ['card' => 'images/credit_cards/Test-MasterCard-Icon.png', 'text' => 'Master Card'], diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 041b26054a72..5fbdf24660b8 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -282,7 +282,7 @@ class Invoice extends BaseModel $status_id = self::STATUS_PAID; } elseif ($paid && $this->balance > 0 && $this->balance < $this->amount) { $status_id = self::STATUS_PARTIAL; - } elseif ($this->isPartial() && $this->balance > 0) { + } elseif ($this->hasPartial() && $this->balance > 0) { $status_id = ($this->balance == $this->amount ? self::STATUS_SENT : self::STATUS_PARTIAL); } @@ -297,10 +297,17 @@ class Invoice extends BaseModel /** * @return bool */ - public function isPartial() : bool + public function hasPartial() : bool { return ($this->partial && $this->partial > 0) === true; - //return $this->status_id >= self::STATUS_PARTIAL; + } + + /** + * @return bool + */ + public function isPartial() : bool + { + return $this->status_id >= self::STATUS_PARTIAL; } /** diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index e3f2cbeb121f..724860a67d72 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -58,7 +58,7 @@ class AccountTransformer extends EntityTransformer { return [ - 'id' => $this->encodePrimaryKey($account->id), + 'id' => (string)$this->encodePrimaryKey($account->id), 'default_url' => config('ninja.site_url'), 'plan' => $account->getPlan(), ]; diff --git a/app/Transformers/CompanyGatewayTransformer.php b/app/Transformers/CompanyGatewayTransformer.php new file mode 100644 index 000000000000..20a04b0d86b7 --- /dev/null +++ b/app/Transformers/CompanyGatewayTransformer.php @@ -0,0 +1,69 @@ + (string)$this->encodePrimaryKey($company_gateway->id), + 'gateway_key' => (string)$company_gateway->gateway_key ?: '', + 'accepted_credit_cards' => (int)$company_gateway->accepted_credit_cards, + 'require_cvv' => (bool)$company_gateway->require_cvv, + 'show_address' => (bool)$company_gateway->show_address, + 'show_shipping_address' => (bool)$company_gateway->show_shipping_address, + 'update_details' => (bool)$company_gateway->update_details, + 'config' => (string)$company_gateway->config ?: '', + 'priority_id' => (int)$company_gateway->priority_id, + 'min_limit' => (float)$company_gateway->min_limit, + 'max_limit' => (float)$company_gateway->max_limit, + 'fee_amount' => (float) $company_gateway->fee_amount, + 'fee_percent' => (float)$company_gateway->fee_percent ?: '', + 'fee_tax_name1' => (string)$company_gateway->fee_tax_name1 ?: '', + 'fee_tax_name2' => (string) $company_gateway->fee_tax_name2 ?: '', + 'fee_tax_rate1' => (float) $company_gateway->fee_tax_rate1, + 'fee_tax_rate2' => (float)$company_gateway->fee_tax_rate2, + 'fee_cap' => (float)$company_gateway->fee_cap, + 'adjust_fee_percent' => (bool)$company_gateway->adjust_fee_percent, + 'updated_at' => $company_gateway->updated_at, + 'deleted_at' => $company_gateway->deleted_at, + ]; + } + +} diff --git a/tests/Integration/UploadLogoTest.php b/tests/Integration/UploadLogoTest.php index 07f9448855ab..c647776317e4 100644 --- a/tests/Integration/UploadLogoTest.php +++ b/tests/Integration/UploadLogoTest.php @@ -56,6 +56,7 @@ class UploadLogoTest extends TestCase ])->put('/api/v1/companies/'.$this->encodePrimaryKey($this->company->id), $data); $response->assertStatus(200); + $acc = $response->json(); $logo = $acc['data']['logo'];