diff --git a/app/Helpers/Mail/GmailTransportManager.php b/app/Helpers/Mail/GmailTransportManager.php index b65fa15d13c4..d6fed2d2fb8d 100644 --- a/app/Helpers/Mail/GmailTransportManager.php +++ b/app/Helpers/Mail/GmailTransportManager.php @@ -12,8 +12,8 @@ class GmailTransportManager extends TransportManager { $token = $this->app['config']->get('services.gmail.token', []); $mail = new Mail; - - return new GmailTransport($mail, string $token); + + return new GmailTransport($mail, $token); } } \ No newline at end of file diff --git a/app/Http/Controllers/ClientController.php b/app/Http/Controllers/ClientController.php index cb724e13f725..cf494504f6ed 100644 --- a/app/Http/Controllers/ClientController.php +++ b/app/Http/Controllers/ClientController.php @@ -351,8 +351,8 @@ class ClientController extends BaseController * path="/api/v1/clients", * operationId="storeClient", * tags={"clients"}, - * summary="Adds a company", - * description="Adds an company to the system", + * summary="Adds a client", + * description="Adds an client to a copmany", * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), diff --git a/app/Http/Controllers/OpenAPI/CompanySchema.php b/app/Http/Controllers/OpenAPI/CompanySchema.php index 90870421c215..26898a88f53c 100644 --- a/app/Http/Controllers/OpenAPI/CompanySchema.php +++ b/app/Http/Controllers/OpenAPI/CompanySchema.php @@ -14,6 +14,7 @@ * @OA\Property(property="enable_invoice_quantity", type="boolean", example=true, description="Toggles filling a product description based on product key"), * @OA\Property(property="convert_products", type="boolean", example=true, description="___________"), * @OA\Property(property="update_products", type="boolean", example=true, description="Toggles updating a product description which description changes"), + * @OA\Property(property="show_product_details", type="boolean", example=true, description="Toggles showing a product description which description changes"), * @OA\Property(property="custom_fields", type="object", description="Custom fields map"), * @OA\Property(property="enable_product_cost", type="boolean", example=true, description="______________"), * @OA\Property(property="enable_product_quantity", type="boolean", example=true, description="______________"), diff --git a/app/Http/Controllers/OpenAPI/InvoiceSchema.php b/app/Http/Controllers/OpenAPI/InvoiceSchema.php index 1188cab414de..3b685acee839 100644 --- a/app/Http/Controllers/OpenAPI/InvoiceSchema.php +++ b/app/Http/Controllers/OpenAPI/InvoiceSchema.php @@ -25,6 +25,7 @@ * @OA\Property(property="tax_rate2", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="tax_name3", type="string", example="", description="________"), * @OA\Property(property="tax_rate3", type="number", format="float", example="10.00", description="_________"), + * @OA\Property(property="total_taxes", type="number", format="float", example="10.00", description="The total taxes for the invoice"), * @OA\Property(property="line_items", type="object", example="", description="_________"), * @OA\Property(property="amount", type="number", format="float", example="10.00", description="_________"), * @OA\Property(property="balance", type="number", format="float", example="10.00", description="_________"), diff --git a/app/Http/Controllers/OpenAPI/QuoteSchema.php b/app/Http/Controllers/OpenAPI/QuoteSchema.php index 75229e49b5a5..d51ce09f1d6d 100644 --- a/app/Http/Controllers/OpenAPI/QuoteSchema.php +++ b/app/Http/Controllers/OpenAPI/QuoteSchema.php @@ -4,5 +4,6 @@ * schema="Quote", * type="object", * @OA\Property(property="id", type="string", example="Opnel5aKBz", description="______"), + * @OA\Property(property="total_taxes", type="number", format="float", example="10.00", description="The total taxes for the quote"), * ) */ \ No newline at end of file diff --git a/app/Http/Controllers/TemplateController.php b/app/Http/Controllers/TemplateController.php index cfe2e51b9bed..784f76bfd443 100644 --- a/app/Http/Controllers/TemplateController.php +++ b/app/Http/Controllers/TemplateController.php @@ -111,10 +111,12 @@ class TemplateController extends BaseController $subject = request()->input('subject'); $body = request()->input('body'); - $body = Parsedown::instance()->text(request()->input('body')); - $subject = Parsedown::instance()->text(request()->input('subject')); + $data = [ + 'subject' => Parsedown::instance()->text(request()->input('subject')), + 'body' => Parsedown::instance()->text(request()->input('body')), + ]; - return response()->json($body, 200); + return response()->json($data, 200); } diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index a7de80bb93d6..09717f23a751 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -44,7 +44,7 @@ class StoreClientRequest extends Request //$rules['name'] = 'required|min:1'; $rules['id_number'] = 'unique:clients,id_number,' . $this->id . ',id,company_id,' . $this->company_id; $rules['settings'] = new ValidClientGroupSettingsRule(); - $rules['contacts.*.email'] = 'distinct'; + $rules['contacts.*.email'] = 'nullable|distinct'; $contacts = request('contacts'); diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index dea98b145be7..0ecc38206e3a 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -44,7 +44,7 @@ class UpdateClientRequest extends Request //$rules['id_number'] = 'unique:clients,id_number,,id,company_id,' . auth()->user()->company()->id; $rules['id_number'] = 'unique:clients,id_number,' . $this->id . ',id,company_id,' . $this->company_id; $rules['settings'] = new ValidClientGroupSettingsRule(); - $rules['contacts.*.email'] = 'distinct'; + $rules['contacts.*.email'] = 'nullable|distinct'; $contacts = request('contacts'); diff --git a/database/migrations/2014_10_13_000000_create_users_table.php b/database/migrations/2014_10_13_000000_create_users_table.php index 36df17e6012e..bd42aa1626fb 100644 --- a/database/migrations/2014_10_13_000000_create_users_table.php +++ b/database/migrations/2014_10_13_000000_create_users_table.php @@ -146,8 +146,10 @@ class CreateUsersTable extends Migration $table->string('company_key',100)->unique(); $table->string('logo')->nullable(); $table->boolean('convert_products')->default(false); - $table->boolean('fill_products')->default(false); - $table->boolean('update_products')->default(false); + $table->boolean('fill_products')->default(true); + $table->boolean('update_products')->default(true); + $table->boolean('show_product_details')->default(true); + $table->boolean('custom_surcharge_taxes1')->default(false); $table->boolean('custom_surcharge_taxes2')->default(false); $table->boolean('custom_surcharge_taxes3')->default(false); diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 09dd91d675c0..330e6d4d2507 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -328,4 +328,126 @@ class PaymentTest extends TestCase } + public function testPaymentGreaterThanPartial() + { + + + $this->invoice = null; + + $client = ClientFactory::create($this->company->id, $this->user->id); + $client->save(); + + $this->invoice = InvoiceFactory::create($this->company->id,$this->user->id);//stub the company and user_id + $this->invoice->client_id = $client->id; + + $this->invoice->partial = 5.0; + $this->invoice->line_items = $this->buildLineItems(); + $this->invoice->uses_inclusive_taxes = false; + + $this->invoice->save(); + + $this->invoice_calc = new InvoiceSum($this->invoice); + $this->invoice_calc->build(); + + $this->invoice = $this->invoice_calc->getInvoice(); + $this->invoice->save(); + $this->invoice->markSent(); + $this->invoice->save(); + + + $data = [ + 'amount' => 6.0, + 'client_id' => $client->hashed_id, + 'invoices' => [ + [ + 'id' => $this->invoice->hashed_id, + 'amount' => 6.0 + ], + ], + 'payment_date' => '2019/12/12', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/payments?include=invoices', $data); + + $arr = $response->json(); + $response->assertStatus(200); + + $payment_id = $arr['data']['id']; + + $payment = Payment::find($this->decodePrimaryKey($payment_id))->first(); + + $this->assertNotNull($payment); + $this->assertNotNull($payment->invoices()); + $this->assertEquals(1, $payment->invoices()->count()); + + $invoice = $payment->invoices()->first(); + + $this->assertEquals($invoice->partial, 0); + $this->assertEquals($invoice->balance, 4); + + } + + public function testPaymentLessThanPartialAmount() + { + + $this->invoice = null; + + $client = ClientFactory::create($this->company->id, $this->user->id); + $client->save(); + + $this->invoice = InvoiceFactory::create($this->company->id,$this->user->id);//stub the company and user_id + $this->invoice->client_id = $client->id; + + $this->invoice->partial = 5.0; + $this->invoice->line_items = $this->buildLineItems(); + $this->invoice->uses_inclusive_taxes = false; + + $this->invoice->save(); + + $this->invoice_calc = new InvoiceSum($this->invoice); + $this->invoice_calc->build(); + + $this->invoice = $this->invoice_calc->getInvoice(); + $this->invoice->save(); + $this->invoice->markSent(); + $this->invoice->save(); + + + $data = [ + 'amount' => 2.0, + 'client_id' => $client->hashed_id, + 'invoices' => [ + [ + 'id' => $this->invoice->hashed_id, + 'amount' => 2.0 + ], + ], + 'payment_date' => '2019/12/12', + ]; + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/payments?include=invoices', $data); + + $arr = $response->json(); + $response->assertStatus(200); + + $payment_id = $arr['data']['id']; + + $payment = Payment::find($this->decodePrimaryKey($payment_id))->first(); + + $this->assertNotNull($payment); + $this->assertNotNull($payment->invoices()); + $this->assertEquals(1, $payment->invoices()->count()); + + $invoice = $payment->invoices()->first(); + + $this->assertEquals($invoice->partial, 3); + $this->assertEquals($invoice->balance, 8); + + } }