I am creating a double entry accounts website in laravel, transaction sale, purchase and cash or bank etc. And i have build the api for an payment website using laravel accounting package eloquent-ifrs , When I create api for add transaction, these trancation is multiple types.
I have all trasaction created expect 'contra entry' transaction because in this transaction main account type not valid for double entry for line item post ledgers.example:-
$contraEntry = ContraEntry::create([
'entity_id' => $entity,
'account_id' => $bankAccount->id,
]);
$zeroVat = DB::table('ifrs_vats')->where('entity_id', $entity)->whereNull('account_id')->first();
$assetAccount = Account::where('account_type', 'BANK')->first();
$contraEntryLineItem = LineItem::create([
'vat_id' => $zeroVat->id,
'account_id' => $assetAccount->id,
'vat_account_id' => $zeroVat->account_id
In this example of code contraEntry transaction created after that lineItem not created. Because A Transaction Main Account cannot be one of the Line Item Accounts.
I have sent parameter account_id for create first ContraEntry::create([]) and required account_type = "BANK" and account_type= "BANK" required in LineItem::create([]) but exist account id can't be send showing this error.
If any one have already worked on this Eloquent IFRS laravel package or working on this "Eloquent IFRS" accounting package.Help me out I really appreciate.
Related
As my diagram, I want to get all the records of table 1 in every tenants from the central domain side. Is that possible to initialize all the tenants at once and take all the records?
Or should I initialize tenants one by one and push records to an array?
I am using the tenancyforlaravel (archtechx/tenancy) package
Updated 1
In tenancyforlaravel tenancy package has a feature to connect tenant DB.It is called initialization. Normally It automatically identifies the database and initializes it by domain address. Also can manually initializes but need to give tenant id. Source link
Finally, I figure out how to do that after long days. It is very very easy with this package. There is a helper function. Only need to use this runForMultiple helper function. below has the example code,
tenancy()->runForMultiple(null, function (Tenant $tenant) {
foreach (Product::get() as $product) {
array_push($this->products, [
'shop_id' => $tenant->id,
'shop_name' => $tenant->name,
'id' => $product->id,
'name' => $product->name,
]);
}
});
I have the following database structure:
Enquiries
id
total_widgets
total_amount
customer_id
Customers
id,
first_name,
last_name
Using the form when you are creating an Enquiry you can enter the Customers details into the section and this will store using firstOrCreate and then get the id in order to link to Enquiry to the Customer
Now, the issue is that this is all done inside the store method within the Customers controller, like the following:
public function store(Request $request)
{
$rules = array(
"first_name" => "required",
"last_name" => "required",
"total_widgets" => "required"
);
// Handle validation
// Create customer
$customer = \App\Customers::firstOrCreate(['first_name' => $request-
>get('first_name')]);
$enquiry = new \App\Enquiries();
$enquiry->customer_id = $customer->id;
$enquiry->save();
}
The issue with doing it like this is that it's not separated out and that if the process of creating a customer changes, then I would need to change this a lot of times. (Everytime I have a section which requires a customer)..
Is there a better way to do this? For example, should the customer be created separately and then the id is passed into the $request?
Another way of doing this is :
1) In Enquiries form add button called "add new customer".
2) When you click on this button a modal will appear and then fill details click submit.
3) On clicking submit make an ajax call to Customercontroller and insert the data then return the last inserted id.
4) Now you can see the new user in drop down box(There will be some drop down for selecting the user) of enquirey form just select it and then press submit.
5) It will passed to the enquirey controller and and store it.
Hope this will help you.
How to display all user invoices for referencing in the admin section of the application.
I can get a user invoices by
$userinvoices = $user->invoices();
Or I can get all invoice by stripe API:
$invoices = \Stripe\Invoice::all(array("limit" => 30));
in the second case, I can't get the details of the user the invoice belongs to.
Or is there any way to save invoice data to database on every creation of the invoice in stripe.
Your first option is the better way to go since you have all the information on the invoice and also the user info on the object.
If you want, you can go to your stripe dashboard -> Your account -> account settings -> webhooks -> add endpoint -> select events and select the invoiceitem.created event. setup your endpoint in the application and do whatever you need with it.
Example:
public function invoiceCreated(Request $request){
$payload = $request->all();
if($payload['type'] == 'invoiceitem.created'){
// do whatever you want with the $payload["data"]...
}
}
Good Luck :)
I have a users table and a one-to-zero/one relation with a businesses table (users.user_id => businesses.user_id). On my users table I have a discriminator which tells me if the user is of type business and therefore I need to have details on the businesses table as well.
I want to create my Users with my factory which currently is working and then only create business details where the discriminator points to a business account.
I have three options in my mind:
Create from users factory and then using '->each()' do some checks on the discriminator and create a new business user using a the factory. However I cannot pass to the business factory the user_id that the user was assigned.
First create the users. Then in my Business seeder, retrieve all Users that match a 'business' discriminator. Then for all of these users run a factory that creates the business details. But again, I would have to link somehow the user_id of the already create user with the business factory user_id.
In my business factory, create a new User and retrieve the id, thus making the link between users.user_id and business.user_id. However I am using a random generator for user.user_type so even if I have the businesses table filled it might be for users that have the discriminator as 'personal'.
Is there another way? Can I pass arguments from my Seeder to the factory?
The attributes you pass to the create function will be passed into your model definition callback as the second argument.
In your case you don't even need to access those attributes, since they'll automatically be merged in:
$business = factory(App\Business::class)->create();
factory(App\User::class, 5)->create([
'business_id' => $business->id,
]);
Adapt this to your needs.
My code for adding polymorphic 'Admin' users was:
// run model factory
factory(App\Admin::class, 3)->create()->each(function ($admin) {
$admin->user()->save(
// solved: https://laravel.com/docs/master/database-testing#using-factories (Overriding attributes)
factory(App\User::class)->make([
'userable_id' => $admin->id,
'userable_type' => App\Admin::class
])
);
});
Hope this helps.
Send attribute,
factory(App\User::class)->create(['businessId' => $businessId]);
Retrieve it,
$factory->define(App\User::class, function (Faker $faker, $businessInfo) {
//$businessInfo['businessId']
});
I am using magento 1.7.0.2. I am having issue regarding store id. When I add new customer from the frontend by sign up, it adds the store id in the "Customer Entity" table. However, when I try to manually add a customer using the backend inserts "0" rather than the 'store id' in the "Customer Entity" table.
How can I get the store id of the customer when adding a customer by admin?
How to set option in backend to insert store id manually in "Customer Entity" table via backend?
Is it required to set new field 'select store'?
It is simple.
go to /app/code/core/Mage/Adminhtml/controllers/CustomerController.php
and just before //send welcome email part
// Mage::dispatchEvent('adminhtml_customer_prepare_save', array(
// 'customer' => $customer,
// 'request' => $this->getRequest()
// ));
And put following code there.
$storeId = $customer->getSendemailStoreId();
Mage::app()->setCurrentStore($storeId);
$customer->save();
That's it now you can choose store from backend and will also be inserted in to customer_entity table.
solution find from phprocks