jeudi 23 août 2018

PHP Monthly Payment Transaction

I am building an application for gym where people can join on different plans .

Here Gym Guy will 1.pay amount in diffrent type means he may be pay two o three months in advance 2.Some might pay parially i mean whenver he has in a month (ex if his monthly plan price is 500 then he may be pay 3 to 4 emi) 3. Some might pay after 4 months (Pending)

Now i need to find out

  1. How many having pending amount till now
  2. How many have given in advance 3.Payment Transaction List 4.I need show each person all month detail(month considered from joining date)

I also decided to update customer_billings using cron based on expire date

I have tried Many methods and removed every think since none of them work as expected.Even i tried distrubting payment amount to each month via FIFO but doesnt work as expected

Database Structure

CREATE TABLE `customers` (
  `id` int(11) NOT NULL,
  `customer_name` varchar(255) DEFAULT NULL,
  `expire_date` datetime DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `customers`
--

INSERT INTO `customers` (`id`, `customer_name`, `expire_date`, `created_at`, `updated_at`) VALUES
(1, 'Alex', '2018-08-10 00:00:00', '2018-08-22 18:30:00', '2018-08-22 18:30:00');

-- --------------------------------------------------------

--
-- Table structure for table `customer_billings`
--

CREATE TABLE `customer_billings` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `start_date` datetime DEFAULT NULL,
  `end_date` datetime DEFAULT NULL,
  `plan_id` int(11) DEFAULT NULL,
  `is_paid` int(11) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `customer_billings`
--

INSERT INTO `customer_billings` (`id`, `customer_id`, `start_date`, `end_date`, `plan_id`, `is_paid`, `created_at`, `updated_at`) VALUES
(1, 1, '2018-05-08 00:00:00', '2018-06-08 00:00:00', 1, NULL, '2018-08-22 18:30:00', '2018-08-22 18:30:00'),
(2, 1, '2018-06-09 00:00:00', '2018-07-09 00:00:00', 1, NULL, '2018-08-22 18:30:00', '2018-08-22 18:30:00'),
(3, 1, '2018-07-10 00:00:00', '2018-08-10 00:00:00', 2, NULL, '2018-08-22 18:30:00', '2018-08-22 18:30:00');

-- --------------------------------------------------------

--
-- Table structure for table `customer_payments`
--

CREATE TABLE `customer_payments` (
  `id` int(11) NOT NULL,
  `customer_id` int(11) DEFAULT NULL,
  `paid_amount` int(11) DEFAULT NULL,
  `amount_carry_forward` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `plans`
--

CREATE TABLE `plans` (
  `id` int(11) NOT NULL,
  `plan_name` varchar(255) DEFAULT NULL,
  `plan_amount` int(11) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `plans`
--

INSERT INTO `plans` (`id`, `plan_name`, `plan_amount`, `created_at`, `updated_at`) VALUES
(1, 'Monthly Plan', 200, '2018-08-23 00:00:00', '2018-08-23 00:00:00'),
(2, 'Quarterly Plan', 500, '2018-08-23 00:00:00', '2018-08-23 00:00:00');

In Php I have

public function index(){

        $response=Customer::with(['customerBilling','customerBilling.billingPlan','customerPayment'])->get();

        echo "<pre>";
        print_r($response->toArray());
    }


Output will be



    Array
(
    [0] => Array
        (
            [id] => 1
            [customer_name] => Alex
            [expire_date] => 2018-08-10 00:00:00
            [created_at] => 2018-08-23 00:00:00
            [updated_at] => 2018-08-23 00:00:00
            [customer_billing] => Array
                (
                    [0] => Array
                        (
                            [id] => 1
                            [customer_id] => 1
                            [start_date] => 2018-05-08 00:00:00
                            [end_date] => 2018-06-08 00:00:00
                            [plan_id] => 1
                            [is_paid] => 
                            [created_at] => 2018-08-23 00:00:00
                            [updated_at] => 2018-08-23 00:00:00
                            [billing_plan] => Array
                                (
                                    [id] => 1
                                    [plan_name] => Monthly Plan
                                    [plan_amount] => 200
                                    [created_at] => 2018-08-23 00:00:00
                                    [updated_at] => 2018-08-23 00:00:00
                                )

                        )

                    [1] => Array
                        (
                            [id] => 2
                            [customer_id] => 1
                            [start_date] => 2018-06-09 00:00:00
                            [end_date] => 2018-07-09 00:00:00
                            [plan_id] => 1
                            [is_paid] => 
                            [created_at] => 2018-08-23 00:00:00
                            [updated_at] => 2018-08-23 00:00:00
                            [billing_plan] => Array
                                (
                                    [id] => 1
                                    [plan_name] => Monthly Plan
                                    [plan_amount] => 200
                                    [created_at] => 2018-08-23 00:00:00
                                    [updated_at] => 2018-08-23 00:00:00
                                )

                        )

                    [2] => Array
                        (
                            [id] => 3
                            [customer_id] => 1
                            [start_date] => 2018-07-10 00:00:00
                            [end_date] => 2018-08-10 00:00:00
                            [plan_id] => 2
                            [is_paid] => 
                            [created_at] => 2018-08-23 00:00:00
                            [updated_at] => 2018-08-23 00:00:00
                            [billing_plan] => Array
                                (
                                    [id] => 2
                                    [plan_name] => Quarterly Plan
                                    [plan_amount] => 500
                                    [created_at] => 2018-08-23 00:00:00
                                    [updated_at] => 2018-08-23 00:00:00
                                )

                        )

                )

            [customer_payment] => Array
                (
                )

        )

)

I am not sure whether my database structure is wrong or any other good method is there to achieve.I hope you guys help me out



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Mv1rrd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire